10 Linux Commands Every Ethical Hacker Should Master

10 Linux Commands Every Ethical Hacker Should Master

Graphical tools are fine for a first look, but they stop being useful the moment you need to filter forty thousand log lines, confirm what a binary really does, or prove that a port is open on a specific interface. That work happens in a shell.

What follows isn't a ranked list of favourites. It's a working set: the commands that show up in nearly every assessment, whether you're triaging files pulled off a compromised host, mapping a lab network, or hunting for a path from a low-privileged account to root. Everything here is safe to run on systems you own. For anything else, get written authorisation first — that is the line between an ethical hacker and a trespasser.

find: File Analysis Starts Here

find walks a directory tree and reports what matches. The syntax feels odd for about a week and obvious afterwards. Four forms worth memorising:

  • find / -name "*.conf" 2>/dev/null — locates configuration files; the redirect hides permission errors that would otherwise bury the real results.
  • find / -type f -perm -4000 2>/dev/null — lists SUID binaries, a classic starting point for privilege escalation.
  • find /home -type f -newermt "2025-01-01" — shows files modified recently, useful right after an incident.
  • find /var/www -name "*.php" -exec grep -l "eval(" {} \; — pairs a directory walk with a quick content check.

Identify before you open

file tells you what something actually is, regardless of its extension: file payload.bin. strings pulls readable text out of a binary, and strings -n 8 image.bin | less keeps only sequences of eight characters or more, which cuts the noise considerably. sha256sum gives you a fingerprint: run sha256sum evidence.img before you analyse anything, then compare it against the vendor's published value. If the hashes differ, stop and find out why before you go further.

grep, cut, sort, uniq: Turning Noise Into Answers

Most log analysis is a pipeline rather than a single command. Read it left to right and each stage narrows the result:

grep -i "failed password" /var/log/auth.log | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | sort | uniq -c | sort -nr | head

That answers a real question — which addresses are failing to log in, and how often. The flags matter: -i ignores case, -v inverts the match, -c counts lines, -r recurses through a directory, -o prints only the matching part, and -E enables extended regular expressions so (error|fail|denied) works without escaping every bracket.

Two habits pay off. Pipe long output through less so you can search inside it. And test your pattern against a small sample first; a regex that matches too much is worse than no filter, because it looks like an answer.

ss, lsof and curl: Networking Without a Browser

ss replaced netstat on modern distributions and runs faster. ss -tulpn shows listening TCP and UDP sockets with the owning process and PID attached — you'll usually need sudo for that last column. ss -tan state established shows what's currently connected. When a port is busy and you don't know why, lsof -i :8080 names the process holding it, which turns a twenty-minute mystery into a two-second fix.

curl reads services the way they actually respond. curl -I https://example.com fetches headers only. curl -s -o /dev/null -w "%{http_code}\n" http://10.0.0.5/ prints nothing but the status code, handy when you're checking a list of hosts. The -k flag, which ignores certificate errors, belongs in a lab and nowhere else: it hides exactly the problem you'd want to catch in production.

tcpdump: Capture First, Interpret Later

Guessing what a service is doing is slower than watching it. tcpdump -i eth0 -nn port 80 captures HTTP traffic on one interface, with -nn suppressing DNS and port-name lookups so the output stays readable.

For anything beyond a quick glance, write to a file: sudo tcpdump -i any -w capture.pcap. You can reopen that in Wireshark later, when you're not under time pressure and can follow a stream properly. Add -c 50 so a forgotten capture doesn't fill your disk, or -A to print payloads as ASCII when you want to read them in the terminal.

Filter early. "host 10.0.0.5 and not port 22" keeps your own SSH session's traffic out of the capture — which matters when you're connected across the network you're capturing.

nmap: Map Before You Walk

Start with nmap -sn 10.0.0.0/24 to see which hosts are alive. Then scan a single target rather than the whole subnet; it's kinder to the network and far easier to interpret.

nmap -sV -sC 10.0.0.5 probes the thousand most common ports, fingerprints the services and runs a set of default scripts. Adding -p- scans all 65,535 ports, which takes a long time — save it for targets that matter. -T4 speeds things up on a responsive network; pushing timing higher than that mostly produces false negatives.

Read the output rather than trusting the summary line. An open port running a version you don't recognise is more interesting than a clean scan.

The Privilege Escalation Loop: id, sudo -l, ps, find

Privilege escalation on a Linux host is mostly enumeration. You're looking for something misconfigured, and this ordered checklist is where that search starts. Run it on a machine you own:

  1. id — know exactly who you are and which groups you belong to. Group membership is often the whole answer.
  2. sudo -l — list what you may run as another user. Look past the obvious binaries; anything that can read or execute files deserves a look at its manual page.
  3. ps aux — see what's running. A root-owned process started from a directory you can write to is worth a second look.
  4. find / -perm -4000 -type f 2>/dev/null

    Photo: 422737 / Pixabay

Related Posts