Linux Essentials for Cyber Security: Commands, Permissions and Logs

Most servers, cloud workloads, security tools and security distributions run on Linux. If you want to work in security, you will spend a great deal of time at a command prompt. The good news is that a small set of commands and ideas covers most daily tasks. This lesson builds that foundation with practice you can do in your lab, on a Linux virtual machine (Kali, Ubuntu or Debian all work).

The File System Layout

DirectoryPurposeWhy security people care
/Root of the file systemEverything starts here
/etcSystem configurationMisconfigurations and credentials often live here
/var/logLogsFirst stop in any investigation
/homeUser filesShell history, keys, documents
/tmpTemporary filesWorld-writable; common place for suspicious files
/bin, /usr/binProgramsTampered binaries are a warning sign
/procLive view of processes and kernelInspect running programs
/rootHome of the administrator accountHighly privileged

Navigation and File Commands

pwd                      # where am I?
ls -la                   # list files, including hidden ones, with permissions
cd /var/log              # change directory
cat /etc/os-release      # view a file
less /var/log/syslog     # page through a long file (q to quit)
head -n 20 file.txt      # first 20 lines
tail -n 20 file.txt      # last 20 lines
tail -f /var/log/syslog  # follow a log live (Ctrl+C to stop)
grep -i "failed" file    # search for text, ignoring case
find / -name "*.conf" 2>/dev/null   # find files by name
man ls                   # manual page for any command

Get used to man and --help. Professionals look things up constantly.

Users, Groups and Permissions

Linux permissions are one of the most testable and most abused concepts in security. Run ls -l and you will see something like:

-rwxr-x---  1 alice developers  2048 Oct 19 10:00 deploy.sh

Read it as: file type (- regular file, d directory), then three triplets for owner, group and others, each with read (r), write (w) and execute (x). Here, alice can read, write and execute; the developers group can read and execute; others have no access.

OctalBinaryMeaning
7111read, write, execute
6110read, write
5101read, execute
4100read only
0000no access
chmod 750 deploy.sh          # owner rwx, group r-x, others none
chmod u+x script.sh          # add execute for the owner
chown alice:developers file  # change owner and group
id                           # who am I and which groups am I in?
whoami                       # current user
sudo -l                      # what may I run with elevated privileges?
cat /etc/passwd              # account list (no password hashes)
sudo cat /etc/shadow         # password hashes; readable only by root

Special permissions

  • SUID (shown as s in the owner triplet): the program runs with its owner’s privileges. Legitimate for tools like passwd, dangerous when applied to the wrong programs.
  • SGID: similar, for the group.
  • Sticky bit (shown as t): in a shared directory such as /tmp, only a file’s owner may delete it.

A defensive audit of your own system lists all SUID programs, so you can review anything unexpected:

find / -perm -4000 -type f 2>/dev/null

Processes and Services

ps aux                    # all running processes
top                       # live process view (q to quit)
ps aux | grep ssh         # find a specific process
kill 1234                 # ask process 1234 to stop
systemctl status ssh      # service status
systemctl list-units --type=service --state=running   # running services
journalctl -u ssh --since "1 hour ago"                # logs for a service

A key security habit is knowing what should be running on a machine. Unknown processes, services and scheduled tasks deserve investigation. List scheduled jobs with crontab -l and by reading /etc/cron*.

Networking Commands

ip addr show              # interfaces and addresses
ip route                  # routing table
ss -tulpn                 # listening TCP/UDP ports and the programs using them
ping -c 4 192.168.56.1    # reachability test
traceroute 192.168.56.1   # path to a host
dig example.com           # DNS lookup
curl -I https://example.com   # fetch HTTP headers only

ss -tulpn is one of the most useful defensive commands: it shows every service listening for connections. If you see a port you cannot explain, find out why it is open.

Text Processing: The Analyst’s Superpower

Logs are text, so text-processing tools become investigation tools. Pipes (|) connect commands, sending the output of one into the next.

# Count failed SSH logins per source address in the authentication log
grep "Failed password" /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr | head

# Show unique user names that appear in failed logins
grep "Failed password" /var/log/auth.log | awk '{print $9}' | sort -u

# Count lines matching a pattern
grep -c "error" /var/log/syslog

# Extract columns from a file
cut -d: -f1,3 /etc/passwd

On some systems the authentication log is /var/log/secure or lives in the journal (journalctl). The exact field positions depend on the log format, so always look at a few lines first, then build the command.

Package Management and Updates

sudo apt update && sudo apt upgrade     # Debian/Ubuntu/Kali
apt list --upgradable                       # what needs patching?
sudo apt install wireshark                  # install a tool
dpkg -l | less                              # list installed packages

Patching is a core security task. A lab habit of updating regularly builds a real-world habit.

Basic Scripting

A tiny script automates a repeated task. Save this as port-check.sh on your lab machine:

#!/bin/bash
# List listening ports and flag anything unusual (edit the allowed list for your machine)
allowed="22 80"
for p in $(ss -tuln | awk 'NR>1 {print $5}' | awk -F: '{print $NF}' | sort -un); do
  if ! echo "$allowed" | grep -qw "$p"; then
    echo "Review port: $p"
  fi
done
chmod +x port-check.sh
./port-check.sh

Learn Bash first, then Python. Python is the dominant language for security automation, parsing and tool development.

Hardening Quick Wins

  • Use SSH keys instead of passwords, and disable root login over SSH.
  • Remove unused packages and disable unused services.
  • Apply updates promptly.
  • Use sudo with named accounts rather than logging in as root.
  • Enable a host firewall (ufw or nftables).
  • Review listening ports and scheduled jobs regularly.

Practice Exercises

  1. Create a user called student, a directory /srv/lab and set permissions so that only student can write to it and the group can read.
  2. Use find to list all files on your VM that are world-writable. Which locations appear, and are they expected?
  3. Run ss -tulpn. For each listening port, identify the program and decide whether it is necessary.
  4. Generate some failed SSH logins against your own VM (use the wrong password a few times from another lab VM), then use grep, awk and sort to count them by source address.
  5. Write a Bash script that prints the five largest files in /var/log.

Mentor tip: Type commands instead of pasting them for the first month. Muscle memory and the small errors you make and fix are where Linux knowledge actually forms.

Educational use only: practise security techniques only on systems you own or have explicit written permission to test.

Key takeaways
  • Know the file system layout, especially /etc, /var/log and /tmp.
  • Permissions (owner, group, others; read, write, execute) and SUID are central security concepts.
  • ss -tulpn, ps and journalctl tell you what a system is doing.
  • Pipes with grep, awk, sort and uniq turn logs into answers.
  • Patch, restrict, and review: simple habits are strong hardening.

Related Lessons