By the end of this lesson you can
- Explain what Linux, GNU and a distribution are and pick a distro for a job
- Navigate the file hierarchy and know what lives in /etc, /var/log, /tmp and /proc
- Use pipes, redirection and chaining to answer questions from logs
- Read and set permissions in symbolic and octal form, and explain SUID, SGID and sticky
- Manage packages, processes and services, and know Linux persistence spots
Why Linux runs the world, and where it came from
If you work in security you will work on Linux. It runs the large majority of web servers and cloud instances, nearly every supercomputer, most routers, smart TVs and CCTV recorders, and the Android kernel on most phones in your college. Most security tools are written for it first.
A short history that explains a lot
- 1969: Ken Thompson and Dennis Ritchie at Bell Labs create Unix. Its ideas (small tools that do one job, plain text files, everything is a file, a multiuser permission model) still shape Linux.
- 1983: Richard Stallman launches the GNU project to build a free Unix like system. By the early 1990s it had a compiler, shell and tools, but no finished kernel.
- 1991: Linus Torvalds, a student in Helsinki, announces a hobby kernel on 25 August. Combined with the GNU tools it became a complete free operating system. The kernel is released under the GPL licence, so anyone can read, change and share it.
Strictly, Linux is only the kernel. What you install is a distribution: the kernel plus GNU tools, a package manager, a desktop or server setup and thousands of programs.
Distributions: which one, and why
| Family | Examples | Package tool | Where you meet it |
|---|---|---|---|
| Debian | Debian, Ubuntu, Linux Mint, Kali Linux | apt, .deb files | most tutorials, many cloud servers, security labs |
| Red Hat | RHEL, Fedora, Rocky Linux, AlmaLinux, CentOS Stream | dnf, .rpm files | banks, enterprises, government data centres |
| Arch | Arch Linux, Manjaro | pacman | enthusiasts who like to build their own system |
| Alpine | Alpine Linux | apk | tiny Docker containers |
| SUSE | openSUSE, SLES | zypper | some enterprises, SAP systems |
Ubuntu LTS (long term support) releases come every two years in April and get five years of standard security updates, which is why servers use them. Kali Linux is a Debian based toolkit for penetration testing by Offensive Security. It is excellent inside a lab VM, but it is not meant to be your everyday desktop.
The file hierarchy: everything is a file
Linux has one tree starting at /, laid out by the Filesystem Hierarchy Standard. Learn it once and you can find your way on any distribution, which is exactly what an investigator or attacker does on an unknown server.
Paths are either absolute, starting from / (/var/log/auth.log), or relative to where you are (../logs). ~ means your home folder, . the current folder, .. the parent. Names are case sensitive: Report.txt and report.txt are different files. Names starting with a dot are hidden from a plain ls.
The shell: talking to Linux
The terminal is the window; the shell is the program inside it that reads your commands. Most systems use bash; macOS and many power users use zsh. A command has a simple shape:
$ ls -la /etc
# command options argument- Options change behaviour: short ones like
-lcan be combined (-la); long ones look like--all. - The shell finds programs by searching each folder in the
PATHvariable in order.which lsshows which file will run. - Help is built in:
man ls,ls --help, andtldr lsif installed.
Pipes and redirection: the real superpower
Every program has three standard streams: input (0, stdin), output (1, stdout) and errors (2, stderr). You can connect them:
| Syntax | Meaning | Example |
|---|---|---|
a | b | send a's output into b's input | cat auth.log | grep Failed |
> file | write output to a file (overwrites) | ls > list.txt |
>> file | append output to a file | echo done >> log.txt |
2>/dev/null | throw error messages away | find / -name '*.conf' 2>/dev/null |
a && b | run b only if a succeeded | sudo apt update && sudo apt upgrade |
*, ? | wildcards matching file names | ls *.log |
Chaining small tools is how analysts answer questions fast. This line counts failed SSH logins per IP address from a log:
$ grep 'Failed password' /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -rnUsers, groups and permissions
Linux is multiuser from the ground up. Users are listed in /etc/passwd (readable by everyone, no passwords inside despite the name), password hashes live in /etc/shadow (readable only by root), and groups in /etc/group.
$ grep student /etc/passwd
student:x:1000:1000:Student,,,:/home/student:/bin/bash
# name : x (hash is in shadow) : UID : GID : comment : home : shellUID 0 is root, all powerful. Normal users start at 1000 on most distributions; lower numbers are system and service accounts, usually with the shell /usr/sbin/nologin. Modern Ubuntu and Debian store passwords as yescrypt hashes (they start with $y$); older systems used SHA-512 ($6$).
Reading and setting permissions
For a directory the bits mean something slightly different: r lets you list names, w lets you create and delete files inside, and x lets you enter it and reach files by name.
| Special bit | Octal | On a file | On a directory |
|---|---|---|---|
| SUID | 4000 | runs with the file owner's privileges (often root); shown as s in the owner x spot | ignored on Linux |
| SGID | 2000 | runs with the file's group | new files inherit the directory's group |
| Sticky | 1000 | no effect today | only a file's owner can delete it, as on /tmp (shown as t) |
sudo lets permitted users run single commands as root, with rules in /etc/sudoers (always edit it with visudo). New files get default permissions from the umask, typically 022 for system accounts and 002 on some desktop setups, giving 644 files and 755 directories.
Packages: installing software safely
Linux installs software from repositories: online collections run by the distribution. Every package is cryptographically signed, and the package manager checks the signature before installing, which is a big security advantage over downloading random installers.
| Task | Debian and Ubuntu | RHEL, Fedora, Rocky |
|---|---|---|
| Refresh the package list | sudo apt update | sudo dnf check-update |
| Install updates | sudo apt upgrade | sudo dnf upgrade |
| Install a package | sudo apt install nmap | sudo dnf install nmap |
| Remove | sudo apt remove nmap | sudo dnf remove nmap |
| Search | apt search wireshark | dnf search wireshark |
| What owns this file? | dpkg -S /usr/bin/ssh | rpm -qf /usr/bin/ssh |
Note that apt update only refreshes the list; apt upgrade actually installs updates. Ubuntu can install security updates automatically through unattended-upgrades. Snap and Flatpak are newer formats that bundle an app with its dependencies.
Processes, services, scheduled jobs and logs
| Want to | Command |
|---|---|
| see every process | ps aux or ps -ef --forest |
| watch live usage | top or htop |
| stop a process politely | kill PID (sends SIGTERM, 15) |
| force stop | kill -9 PID (SIGKILL, cannot be caught) |
| see network listeners and their programs | sudo ss -tulnp |
| see open files of a process | sudo lsof -p PID |
Most distributions use systemd as PID 1. It starts and supervises services (units):
$ systemctl status ssh
$ sudo systemctl enable --now ssh
$ systemctl list-units --type=service --state=running
$ journalctl -u ssh --since '1 hour ago'Scheduled jobs run through cron (crontab -l for your own, /etc/crontab and /etc/cron.d/ for the system) and systemd timers (systemctl list-timers).
Missions 0/6
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 file can every user read but contains no password hashes?
/etc/passwd is world readable; hashes moved to /etc/shadow long ago.
Q2A script shows -rwxr-x--x. What octal mode is that?
rwx = 7, r-x = 5, --x = 1.
Q3Why is /tmp interesting during an investigation?
World writable locations like /tmp and /dev/shm are common drop points.
Q4What does 2>/dev/null do?
Stream 2 is stderr; /dev/null discards it.
Q5A user's sudo rule allows NOPASSWD: /usr/bin/vim. Why is that dangerous?
Many editors and tools can spawn a shell; GTFOBins lists them.
Q6Which is a common Linux persistence location?
Adding a public key there gives the attacker passwordless SSH access.
Hands-on lab
Lab: theory into muscle memory
You need: Your Ubuntu VM. The full hands-on lab is lesson 2.2; this one checks the theory.
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).
Walk the tree
$ cd / && ls $ ls -la /etc | head -20 $ ls /var/log $ cat /proc/versionFor each top level folder, say in one line what it holds without looking at this page.
Read the account files
$ cat /etc/passwd $ awk -F: '$3==0' /etc/passwd $ sudo head -3 /etc/shadow $ getent group sudoCount accounts with a real login shell versus
nologin. Check that only root has UID 0. Note the$y$hash prefix.Audit permissions
$ find / -perm -4000 -type f 2>/dev/null $ sudo -l $ ls -ld /tmpWrite down the SUID programs you find (passwd, sudo, su and mount are normal) and the
tat the end of /tmp's permissions.Check persistence spots on your own VM
$ crontab -l $ ls /etc/cron.d /etc/cron.daily $ systemctl list-unit-files --state=enabled | head -30 $ ls -la ~/.ssh 2>/dev/nullThis is the baseline of a clean machine. Save the output to a file; comparing against a baseline is how you spot changes later.
You are done when: You can explain the purpose of each top level folder, read a passwd line, convert a permission string to octal, and list where Linux persistence hides.
Key takeaways
- Linux is a kernel; distributions turn it into a usable system.
- /etc for config, /var/log for evidence, /tmp for things that should not be there.
- Pipes turn small tools into an analysis engine.
- rwx for owner, group and others; SUID and bad sudo rules are the classic escalation paths.
- cron, systemd, .bashrc and authorized_keys are where intruders persist.
Finished the sections, quiz and lab? Mark the lesson complete. Progress is saved only in this browser.