EPISODE · Oct 31, 2025 · 9 MIN
Series 4: Ep 7: Debugging Your Code
from Learn As I Learn · host Akanksha Pathak
Don't let errors stop you! This episode focuses on practical debugging techniques for both PowerShell and Bash scripts. We'll intentionally introduce common errors (like typos or wrong parameters) and walk through how to identify and fix them, building crucial troubleshooting skills.Powershell Script:#Script to log multiple event IDs$BeginTime = (Get-Date).AddMinutes(-20)Get-EventLog -LogName "Securityy" -After $BeginTime |Where-Object { $_.EventID -in '4624', '4625'} |Select-Object TimeGenerated, EventID, Message |Format-Table -AutoSize |Out-Files C:\EventLogs_MultipleEvents.txtBASH Script:#!/bin/bash#VariablesUSERNAME="testuser" # User accountnamePASSWORD="P@ssw0rd" # User passwordGROUP="testgroup" # Custom groupnameSSH_DIR="/home/$USERNAME/.ssh"PUB_KEY="ssh-rsa AAAAB3...your-public-key... user@kali"#Step 1: Check ifuser already existsif id "$USERNAME" &>/dev/null; then echo "Error: User '$USERNAME'already exists!" exit 1fi#Step 2: Create userand set passwordecho "Creating user '$USERNAME'..."useradd -m -n -s /bin/bash "$USERNAME" # Error 1: -n is an invalidoptionif [ $? -ne 0 ]; then echo "Error: Failed to create user'$USERNAME'" exit 1fiecho "$USERNAME:$PASSWORD" | chpasswdecho "Password set for user '$USERNAME'."#Step 3: Add user tosudoersecho "Granting sudo access to '$USERNAME'..."usermod -aG sudo "$USERNAME"if [ $? -ne 0 ]; then echo "Error: Failed to add'$USERNAME' to sudoers" exit 1fi#Step 4: Createcustom group and add userecho "Creating group '$GROUP' and adding user..."groupadd "$GROUP" 2>/dev/nullusermod -aG "wronggroup" "$USERNAME" # Error 2:"wronggroup" does not existif [ $? -ne 0 ]; then echo "Error: Failed to add'$USERNAME' to group '$GROUP'" exit 1fi#Step 5: Setup SSHkey-based authenticationecho "Setting up SSH key-based authentication..."mkdir -p "$SSH_DIR"echo "$PUB_KEY" > "$SSH_DIR/authorized_keys"chmod 600 "$SSH_DIR/authorized_keys"chmod 700 "$SSH_DIR"chown -R "$USERNAME:$USERNAME" "$SSH_DIR"if [ $? -ne 0 ]; then echo "Error: Failed to set up SSHkeys" exit 1fiecho "SSH keys configured for '$USERNAME'."#Step 6: Setpassword expiry to 30 daysecho "Setting password expiry policy for '$USERNAME'..."chage -M 30 "$USERNAME"if [ $? -ne 0 ]; then echo "Error: Failed to setpassword expiry" exit 1fi#Step 7: Logactivity to/var/log/user_setup.logLOG_FILE="/var/log/user_setup.log"echo "$(date) - User '$USERNAME' created and configured" >>"$LOG_FILE"if [ $? -ne 0 ]; then echo "Error: Failed to write logto $LOG_FILE" exit 1fi#Step 8:Confirmation Messageecho "Testing SSH connection to '$USERNAME'@localhosts..."ssh "$USERNAME@localhost"if [ $? -ne 0 ]; thenecho "Error: SSH connection failed."exit 1fiecho "User '$USERNAME' created and configured successfully!"
What this episode covers
Don't let errors stop you! This episode focuses on practical debugging techniques for both PowerShell and Bash scripts. We'll intentionally introduce common errors (like typos or wrong parameters) and walk through how to identify and fix them, building crucial troubleshooting skills.Powershell Script:#Script to log multiple event IDs$BeginTime = (Get-Date).AddMinutes(-20)Get-EventLog -LogName "Securityy" -After $BeginTime |Where-Object { $_.EventID -in '4624', '4625'} |Select-Object TimeGenerated, EventID, Message |Format-Table -AutoSize |Out-Files C:\EventLogs_MultipleEvents.txtBASH Script:#!/bin/bash#VariablesUSERNAME="testuser" # User accountnamePASSWORD="P@ssw0rd" # User passwordGROUP="testgroup" # Custom groupnameSSH_DIR="/home/$USERNAME/.ssh"PUB_KEY="ssh-rsa AAAAB3...your-public-key... user@kali"#Step 1: Check ifuser already existsif id "$USERNAME" &>/dev/null; then echo "Error: User '$USERNAME'already exists!" exit 1fi#Step 2: Create userand set passwordecho "Creating user '$USERNAME'..."useradd -m -n -s /bin/bash "$USERNAME" # Error 1: -n is an invalidoptionif [ $? -ne 0 ]; then echo "Error: Failed to create user'$USERNAME'" exit 1fiecho "$USERNAME:$PASSWORD" | chpasswdecho "Password set for user '$USERNAME'."#Step 3: Add user tosudoersecho "Granting sudo access to '$USERNAME'..."usermod -aG sudo "$USERNAME"if [ $? -ne 0 ]; then echo "Error: Failed to add'$USERNAME' to sudoers" exit 1fi#Step 4: Createcustom group and add userecho "Creating group '$GROUP' and adding user..."groupadd "$GROUP" 2>/dev/nullusermod -aG "wronggroup" "$USERNAME" # Error 2:"wronggroup" does not existif [ $? -ne 0 ]; then echo "Error: Failed to add'$USERNAME' to group '$GROUP'" exit 1fi#Step 5: Setup SSHkey-based authenticationecho "Setting up SSH key-based authentication..."mkdir -p "$SSH_DIR"echo "$PUB_KEY" > "$SSH_DIR/authorized_keys"chmod 600 "$SSH_DIR/authorized_keys"chmod 700 "$SSH_DIR"chown -R "$USERNAME:$USERNAME" "$SSH_DIR"if [ $? -ne 0 ]; then echo "Error: Failed to set up SSHkeys" exit 1fiecho "SSH keys configured for '$USERNAME'."#Step 6: Setpassword expiry to 30 daysecho "Setting password expiry policy for '$USERNAME'..."chage -M 30 "$USERNAME"if [ $? -ne 0 ]; then echo "Error: Failed to setpassword expiry" exit 1fi#Step 7: Logactivity to/var/log/user_setup.logLOG_FILE="/var/log/user_setup.log"echo "$(date) - User '$USERNAME' created and configured" >>"$LOG_FILE"if [ $? -ne 0 ]; then echo "Error: Failed to write logto $LOG_FILE" exit 1fi#Step 8:Confirmation Messageecho "Testing SSH connection to '$USERNAME'@localhosts..."ssh "$USERNAME@localhost"if [ $? -ne 0 ]; thenecho "Error: SSH connection failed."exit 1fiecho "User '$USERNAME' created and configured successfully!"
NOW PLAYING
Series 4: Ep 7: Debugging Your Code
No transcript for this episode yet
Similar Episodes
Mar 26, 2026 ·1m
Mar 19, 2026 ·34m
Mar 3, 2026 ·44m
Feb 21, 2026 ·30m
Feb 18, 2026 ·11m
Feb 11, 2026 ·45m