Cheat sheet

Linux essentials

The locations, logs and commands to know to administer, investigate or respond to an incident on a Linux machine.

CJCADefence

Key files and folders

PathContent
/etc/passwdUser accounts (without passwords)
/etc/shadowPassword hashes, readable by root only
/etc/groupGroups and their members
/etc/sudoerssudo rights (edit with visudo)
/etc/crontab, /etc/cron.*System scheduled tasks
/etc/systemd/systemsystemd services and timers
/etc/hostsLocal name resolution
~/.ssh/authorized_keysPublic keys allowed to log in
~/.bash_historyThe user's command history
/tmp, /dev/shmWorld-writable temporary folders
/procInformation about running processes

Logs

LogContent
/var/log/auth.logAuthentication, sudo, SSH (Debian, Ubuntu)
/var/log/secureEquivalent on RHEL, CentOS, Fedora
/var/log/syslogGeneral system log (Debian, Ubuntu)
/var/log/messagesGeneral log (RHEL and derivatives)
/var/log/wtmpLogon history (read with last)
/var/log/btmpFailed logons (read with lastb)
/var/log/audit/audit.logauditd events
journalctlThe systemd journal

Permissions

NotationMeaning
r / w / xRead (4) / write (2) / execute (1)
755rwxr-xr-x: everything for the owner, read and execute for others
644rw-r--r--: a regular file
600rw-------: owner only (private keys)
SUID (4000)The program runs with its owner's rights
SGID (2000)Runs with the group's rights; group inheritance on a folder
Sticky bit (1000)In a folder, only the owner can delete their files (/tmp)

Investigation commands

# Who is logged in, who has logged in
w ; last -a | head ; lastb | head
# Processes and tree
ps auxf
# Network connections and listening ports
ss -tulpn
# Scheduled tasks of every user
ls -la /etc/cron.* ; for u in $(cut -d: -f1 /etc/passwd); do crontab -l -u "$u" 2>/dev/null; done
# Active services and timers
systemctl list-units --type=service --state=running ; systemctl list-timers
# Files modified in the last 24 hours
find / -xdev -mtime -1 -type f 2>/dev/null
# SSH journal since yesterday
journalctl -u ssh --since yesterday