Ethical Hacking Series, Part 4. So far we’ve built a Kali lab, learned to move around and manage files, and covered users, groups and permissions. This part answers a question that comes up the moment you land on an unfamiliar Linux machine: where is everything?
Linux puts things in predictable places. Configuration lives in one directory, logs in another, user files in a third. Once you know the layout, you can walk onto any server, in your own lab or during an authorised test, and find the config files, credentials and logs that matter within minutes. The second half of this post covers the four text tools that turn huge files into useful answers: cut, grep, awk and sed.
The root directory
Everything starts at /, the root of the file system. There are no drive letters like on Windows. Other disks and USB drives are attached (mounted) somewhere inside this one tree. Run ls / and you’ll see the directories below.
Where things live
/home and /root
Each regular user gets a directory under /home, such as /home/kali. The root user is the exception: its home is /root, outside /home entirely. Home directories are worth checking on any system you assess, because they hold shell history, SSH keys in .ssh/, and sometimes scripts or notes containing passwords.
/etc
/etc holds configuration for the system and its services. In the video I look at Nginx (/etc/nginx/) and MySQL (/etc/mysql/). Other files you’ll keep coming back to are /etc/passwd and /etc/shadow from Part 3, /etc/ssh/sshd_config for SSH settings, and /etc/hosts. If you want to understand how a service is set up, or whether it’s set up insecurely, start here.
/var and /var/log
/var is for data that changes while the system runs, such as logs, caches, mail and often website files under /var/www. The most useful part for security work is /var/log. Nginx writes every request to /var/log/nginx/access.log and every problem to /var/log/nginx/error.log. During an investigation, the access log tells you which IPs hit the server, what they requested and when. That’s how you spot scanners, brute-force attempts and requests for files like /.env.
/tmp
Temporary files go in /tmp, and on most systems it’s cleared on reboot. Every user can write there, which makes it a common place for attackers to drop tools and scripts after getting in. When you check a system for signs of compromise, look in /tmp (and /dev/shm) for anything that doesn’t belong.
/bin and /usr/local/bin
/bin holds essential commands like ls, cp and cat. On modern distributions, including Kali, /bin is actually a link to /usr/bin. Your own scripts and manually installed tools belong in /usr/local/bin. It’s already in the PATH, so anything you put there can be run by name from anywhere, and it’s kept separate from what the package manager installs.
/boot and /lib
/boot contains what the system needs to start: the Linux kernel, the initial RAM disk and the bootloader files. Don’t delete anything here. /lib holds the shared libraries that programs in /bin depend on, much like DLLs on Windows.
/mnt and /media
These are mount points for extra storage. /media is where USB drives and other removable media usually appear automatically, and /mnt is the traditional place to mount a disk or network share by hand.
/dev
In Linux, hardware shows up as files in /dev. Your first disk is typically /dev/sda, with its partitions as /dev/sda1, /dev/sda2 and so on. Run lsblk to see them as a tree.
/proc
/proc isn’t stored on disk at all. It’s a virtual file system the kernel generates on the fly, showing live information about the system and every running process:
cat /proc/cpuinfo
cat /proc/meminfo
ls /proc/1
Each numbered directory is a running process, named by its process ID. Tools like ps and top read their information from here.
Text processing: the real superpower
Logs and config files can run to thousands or millions of lines. Scrolling through them isn’t an option. These four tools let you pull out exactly what you need, and they work on files or on the output of other commands through a pipe (|).
cut: pull out columns
cut splits each line on a delimiter and gives you the fields you ask for. In /etc/passwd, fields are separated by colons, so this lists every username:
cut -d: -f1 /etc/passwd
In an Nginx access log, fields are separated by spaces and the client IP comes first. Combined with sort and uniq, this shows which IPs sent the most requests, which is a quick way to spot a scanner or a brute-force attempt:
cut -d' ' -f1 /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
grep: find matching lines
grep prints only the lines that match a pattern. Add -i to ignore case, which matters because “Error”, “error” and “ERROR” all appear in real logs:
grep -i "error" /var/log/nginx/error.log
grep "/.env" /var/log/nginx/access.log
grep -i "password" /etc/ssh/sshd_config
awk: fields plus logic
awk goes further than cut. It splits lines into fields ($1, $2, $3…) and lets you add conditions. Remember from Part 3 that system accounts have UIDs below 1000. The UID is the third field of /etc/passwd, so this lists the system accounts:
awk -F: '$3 < 1000 {print $1, $3}' /etc/passwd
Flip the condition to $3 >= 1000 and you get the real human users, which is one of the first things to check on a new system. Here’s another useful one, listing every account with UID 0. There should only ever be one, and it should be root:
awk -F: '$3 == 0 {print $1}' /etc/passwd
sed: edit without opening an editor
sed edits text as it streams through. With -i it changes the file in place, which is perfect for scripts and quick fixes on servers where you don’t want to open vi. In the video I use it to turn off SSH password logins:
sudo sed -i 's/^#\?PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
grep PasswordAuthentication /etc/ssh/sshd_config
sudo sshd -t && sudo systemctl restart ssh
Two safety habits: use -i.bak instead of -i to keep a backup copy of the original file, and run sshd -t to test the configuration before restarting. Most importantly, make sure key-based login works first (we set that up in Part 2). Otherwise you’ll lock yourself out of the server.
Practice tasks
- Run
ls /, then open three directories you haven’t explored before and work out what’s in them. - List all real users on your Kali machine with
awk, and confirm that only root has UID 0. - Generate some traffic to a local Nginx server, then find the top IPs in the access log with
cut,sortanduniq. - On a test VM, use
sed -i.bakto change a setting in a config file, then compare the two versions withdiff. - Check
/tmpand/dev/shmon your system and make sure you recognise everything there.
A note on ethics: explore only your own lab machines or systems you have written permission to test.
What’s next
You now know where things live on a Linux system and how to search them quickly. Next, Part 5 puts these tools to work on real Nginx logs, and covers zip and tar archives, installing tools with apt and dnf, and network checks with ping, nslookup and traceroute. Catch up on the earlier parts if you missed them: Part 1: Kali Linux Lab Setup, Part 2: Linux Commands Every Ethical Hacker Must Know and Part 3: Linux Users, Groups & Permissions. For more practical commands on real servers, see Linux troubleshooting commands with real examples.
Watch Part 4 on my YouTube channel, Madhukar Reddy (@awsandevops).
