Live lesson · progress saved to your account

Linux Fundamentals

The terminal, the file system, permissions and SUID, users and sudo, processes and cron, and log hunting with grep and pipes. Ends with an audit of a web server someone else set up.

beginner120 minwalkthrough

Anyone can read this lesson. To submit answers and earn XP, create a free account.

TASK 01Mission briefing: the inherited server

HANDOVER · SAHYADRI-OPS-1128 Sahyadri Couriers (a fictional logistics company in Pune) runs its parcel-tracking website on a single Linux server, web01. The admin who built it, Prakash, left in October. Since last week the site is slow, and the hosting provider sent a warning about "abnormal CPU usage".

You've been given SSH access as the user deploy. Nobody knows exactly what's on the box.

Over 90% of cloud servers run Linux. So do most firewalls, routers, Android phones and nearly every security tool you'll use: Nmap, Wireshark, Burp, Metasploit. Attackers and defenders both live in the terminal.

You'll connect like this:

ssh deploy@web01.sahyadri.example
deploy@web01:~$

That prompt tells you a lot: who you are (deploy), which machine (web01), where you are (~ = your home folder) and $ = a normal user (root's prompt ends in #).

Your audit checklist (you'll answer all of it by the end):

  • Is any file writable by everyone that shouldn't be?
  • Is there an unknown account with sudo rights?
  • Is someone brute-forcing SSH, and did they get in?
  • What's eating the CPU?

Start by learning the map of the system.

Answer the questions

+10 XP

+10 XP

TASK 02The shell and the file system

Linux has one tree of folders that starts at / (called "root"). There are no C: or D: drives: disks are attached ("mounted") somewhere inside the tree.

Type cd commands, or click folders, and watch where you go:

The Linux file system Type cd or click

deploy@web01:~$

$

Type a cd command, or click a folder.

/var/log absolute: starts at /

../etc relative: from where you are

~ your home · .. one level up

The folders you must know (the FHS)

PathWhat lives thereWhy a security person cares
/etcConfigurationUsers, sudo rules, SSH settings, cron jobs
/homeUsers' personal foldersNotes, SSH keys, shell history
/rootroot's homeOff-limits to everyone else
/var/logLogsEvidence of every login and attack
/var/wwwWebsitesConfig files with database passwords
/tmpTemporary filesWritable by everyone: malware's favourite hiding place
/usr/bin, /binProgramsWhere SUID binaries hide

Moving around

  • pwd: print working directory (where am I?)
  • ls: list files · ls -l long format · ls -a include hidden files (names starting with .)
  • cd /var/log: an absolute path, starting from /
  • cd ../etc: a relative path, from where you are. .. = one level up, . = here, ~ = home

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 03Working with files
CommandDoes
cat filePrint a whole file
less fileScroll through a big file (q to quit, /word to search)
head -n 5 file / tail -n 5 fileFirst / last lines
tail -f fileFollow a log live as new lines arrive
cp a b · mv a b · rm aCopy, move/rename, delete (no recycle bin!)
mkdir dir · touch fileMake a folder, make an empty file
find / -name "*.conf"Search the whole system by name

Wildcards: * matches anything, ? matches one character. ls /var/log/*.log lists every .log file.

Hidden files start with a dot: .bash_history (every command a user typed), .ssh/ (their keys), .bashrc (runs at every login, a common place for attackers to plant persistence).

Careful: rm -rf / deletes everything. Linux assumes you know what you're doing. Never paste commands from the internet that you don't understand, which is also how a lot of malware gets installed (curl … | bash).

Errors you'll see

  • No such file or directory: typo or wrong path. Use Tab to autocomplete.
  • Permission denied: you're not allowed. That's the next task.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

TASK 04Permissions

Every file has an owner, a group, and three sets of permissions: for the user (owner), the group, and others (everyone else).

LetterOn a fileOn a folderValue
rRead itList what's inside4
wChange itCreate/delete files inside2
xRun itEnter it (cd)1

Add the values for each set: rwx = 7, r-x = 5, rw- = 6, r-- = 4. So chmod 755 means rwxr-xr-x.

Click the bits:

Permission bits, live Click the bits

User (owner)

6

Group

4

Other

4

$ chmod 644 config.php

$ ls -l

-rw-r--r-- 1 root www-data 412 Nov 28 02:14 config.php

Reading ls -l

-rw-rw-rw- 1 www-data www-data 412 Nov 28 02:14 config.php
│└┬┘└┬┘└┬┘   └─owner─┘ └group─┘
│ user group other
└ - file, d directory

Changing them

  • chmod 640 config.php: set by number
  • chmod o-w config.php: remove write from others
  • chown www-data:www-data file: change owner and group (needs root)

Special bits

  • SUID (s in the user's x spot, value 4000): the program runs as its owner. /usr/bin/passwd needs this to write /etc/shadow.
  • SGID (2000): runs as the group, or new files inherit the folder's group.
  • Sticky bit (t, 1000): in a shared folder, only a file's owner can delete it. That's why /tmp is rwxrwxrwt.

Why SUID is a big deal: if a root-owned program that can run other commands (find, vim, python, bash) has SUID, any user becomes root with one command. The website GTFOBins lists these. Finding them is step one of Linux privilege escalation: find / -perm -4000 2>/dev/null.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 05Users, groups and sudo

Linux keeps accounts in plain text files. Click through each field:

Read the account files Click a field

/etc/passwd

::::::

Username. The login name.

FileHoldsWho can read it
/etc/passwdEvery account: name, UID, home, shellEveryone
/etc/shadowPassword hashesOnly root
/etc/groupGroups and their membersEveryone
/etc/sudoers and /etc/sudoers.d/Who may use sudo, for whatroot (should be)

UID 0 is root. The name doesn't matter: an account called backup with UID 0 is root.

sudo

sudo command runs one command as root, after asking your password, and logs it to /var/log/auth.log. Run sudo -l to see what you're allowed to do.

Least privilege on Linux:

  • Give each person their own account, never a shared root password.
  • Grant sudo for specific commands (/usr/bin/systemctl restart nginx), not ALL.
  • Service accounts get /usr/sbin/nologin as their shell.
  • Disable direct root login over SSH (PermitRootLogin no).

A line like svc-backup ALL=(ALL) NOPASSWD: ALL gives full root without even a password prompt. If you didn't create it, someone else did.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 06Processes, services and cron

A process is a running program with a PID (process ID), an owner, and a parent that started it.

CommandShows / does
ps auxEvery process, with user, CPU and memory
ps aux --forest / pstreeWho started whom
top / htopLive view sorted by CPU
kill PID / kill -9 PIDAsk a process to stop / force it
systemctl status nginxIs a service (background daemon) running?
crontab -l · cat /etc/crontabScheduled jobs

Something on web01 is using a lot of CPU. Try to stop it:

ps aux --forest · web01 Try to stop the miner

USER PID %CPU COMMAND

root 1 0.0 /sbin/init

root 640 0.1 \_ /usr/sbin/sshd -D

root 702 0.0 \_ nginx: master process

www-data 703 0.3 \_ nginx: worker process

root 715 0.0 \_ /usr/sbin/cron -f

www-data 2270 91.0 \_ /tmp/.x/kworkerd -o pool.example-mine.net:3333

CPU 91.0% · cron runs /tmp/.x/update.sh in 8s

A process called kworkerd (pretending to be a kernel worker) is eating 90%+ CPU. Its parent is cron, not the kernel. Try killing it.

Cron syntax

*/5  *  *  *  *   www-data  /tmp/.x/update.sh
min hour day month weekday  user   command

*/5 in the minute field = every 5 minutes.

Persistence is how attackers survive reboots and clean-ups: cron jobs, systemd services, .bashrc, SSH keys in authorized_keys. Killing the process is only half the job. Always ask "what started it?"

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 07Text power tools and logs

Logs are just text, and Linux has brilliant text tools. The pipe | sends one command's output into the next:

Pipes: each command feeds the next Stage 1/6
|||||
33
27
27
27
2
2

Nov 28 01:58:02 web01 CRON[2190]: pam_unix(cron:session): session opened for user root by (uid=0)

Nov 28 01:59:40 web01 sshd[2201]: Accepted publickey for deploy from 10.0.5.20 port 50122 ssh2

Nov 28 02:01:10 web01 sshd[2210]: Failed password for root from 198.51.100.23 port 40100 ssh2

Nov 28 02:01:17 web01 sshd[2211]: Failed password for root from 198.51.100.23 port 40101 ssh2

Nov 28 02:01:24 web01 sshd[2212]: Failed password for root from 198.51.100.23 port 40102 ssh2

Nov 28 02:03:00 web01 sshd[2213]: Failed password for svc-backup from 203.0.113.77 port 51200 ssh2

Nov 28 02:03:09 web01 sshd[2214]: Failed password for svc-backup from 203.0.113.77 port 51201 ssh2

Nov 28 02:03:18 web01 sshd[2215]: Failed password for root from 203.0.113.77 port 51202 ssh2

Nov 28 02:03:27 web01 sshd[2216]: Failed password for svc-backup from 203.0.113.77 port 51203 ssh2

Nov 28 02:03:36 web01 sshd[2217]: Failed password for svc-backup from 203.0.113.77 port 51204 ssh2

Nov 28 02:03:45 web01 sshd[2218]: Failed password for root from 203.0.113.77 port 51205 ssh2

Nov 28 02:04:54 web01 sshd[2219]: Failed password for svc-backup from 203.0.113.77 port 51206 ssh2

… 21 more

33 lines of everything: cron jobs, logins, sudo.

ToolDoes
grep "word" fileKeep matching lines (-i ignore case, -v invert, -c count)
wc -lCount lines
sort / sort -nrSort / numerically, biggest first
uniq -cMerge repeated adjacent lines and count them (so sort first)
awk '{print $11}'Print the 11th space-separated field
cut -d : -f 1Split on : and keep field 1

Reading auth.log

/var/log/auth.log (on Red Hat-style systems, /var/log/secure) records every SSH login, sudo and su:

Nov 28 02:03:00 web01 sshd[2213]: Failed password for svc-backup from 203.0.113.77 port 51200 ssh2
Nov 28 02:08:31 web01 sshd[2238]: Accepted password for svc-backup from 203.0.113.77 port 51290 ssh2

Dozens of Failed password lines from one IP, followed by an Accepted from the same IP, is the signature of a successful brute force. Watch one happen, and how defences stop it:

tail -f /var/log/auth.log Pick a defence

Failures from 203.0.113.77

0

Attacker status

guessing…

Server

safe

Defences: SSH keys only (PasswordAuthentication no), PermitRootLogin no, fail2ban to ban IPs after a few failures, and strong unique passwords for anything that still uses them.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 08Lab: Linux first contact

You're logged into web01 as deploy. Work through the 15 tasks on the right: each one ticks itself when you run a command that does it.

Linux first contact · 15 tasks 0/15 done

Sahyadri Couriers · web01 · Ubuntu 22.04 LTS

Last login: Thu Nov 28 01:59:40 2026 from 10.0.5.20

deploy@web01:~$

Type help for commands. ↑ repeats. Pipes work: grep … | wc -l

  1. 1. Print where you are
  2. 2. List your home folder
  3. 3. Show hidden files too
  4. 4. Read the handover notes
  5. 5. Move into /etc
  6. 6. Read the user list (/etc/passwd)
  7. 7. Show only users with a bash shell
  8. 8. See who is in the sudo group
  9. 9. Read the extra sudo rule in /etc/sudoers.d
  10. 10. Try reading /etc/shadow (it should fail)
  11. 11. Count failed SSH logins in auth.log
  12. 12. Rank attacking IPs with a pipe (… | sort | uniq -c | sort -nr)
  13. 13. Find SUID binaries
  14. 14. Find world-writable files
  15. 15. List processes and read the system crontab

Hints if you're stuck:

  • Task 7: grep bash /etc/passwd
  • Task 11: grep "Failed password" /var/log/auth.log | wc -l
  • Task 12: grep "Failed password" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -nr
  • Task 13: find / -perm -4000 2>/dev/null (the 2>/dev/null hides "Permission denied" noise)
  • Task 14: find / -perm -o+w -type f 2>/dev/null

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 09Final mission: the audit report

Write up web01 for Sahyadri Couriers' manager. Put your findings together:

  1. Initial access: someone brute-forced SSH. From which IP, into which account?
  2. The account: svc-backup isn't in Prakash's notes. Which sudo rule gives it full root, and in which file?
  3. Impact: what did they install, and how does it survive being killed?
  4. Exposure: which file is world-writable, and what secret does it contain?
  5. Privilege escalation risk: which SUID binary would let any local user become root?

The story: the attacker guessed svc-backup's weak password (PasswordAuthentication yes was still on, despite Prakash's TODO), used its NOPASSWD: ALL sudo rule to become root, dropped a crypto-miner disguised as kworkerd in /tmp/.x, and added a cron job to keep it running. That's why the CPU was pegged.

Fix list: lock and remove svc-backup and its sudoers file; remove the cron line and /tmp/.x; chmod 640 config.php and change the database password; chmod u-s /usr/bin/find; set PasswordAuthentication no and PermitRootLogin no; install fail2ban; and because root was compromised, plan to rebuild the server from a clean image.

Complete the mission for the Shell Shocked badge and 440 XP.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP