Forensics Beginner Linux / CLI / DFIR

Linux Commands � Security Reference

An essential Linux CLI reference for security analysts � file system navigation, user and process investigation, network analysis, log searching, and persistence hunting commands.

14 min read Command Reference Blue Team / DFIR

// Users & Permissions

CommandDescription
idCurrent user's UID, GID, and group memberships
whoamiCurrent username
wWho is currently logged in and what they're running
lastRecent logins from /var/log/wtmp
lastbFailed login attempts from /var/log/btmp
cat /etc/passwdAll user accounts � look for unexpected shell users or unusual UIDs
cat /etc/shadowPassword hashes (root only) � check for recently changed passwords
cat /etc/groupGroup memberships � check sudo, wheel, docker groups for unexpected members
sudo -lWhat commands current user can run via sudo
cat /etc/sudoersSudo configuration � look for NOPASSWD entries
getent passwd | awk -F: '$3==0'Find all UID 0 (root-equivalent) accounts
chage -l usernamePassword expiry and last change date for a user

// Processes & Services

CommandDescription
ps auxAll running processes with user, PID, CPU, memory, command
ps auxfSame but showing parent-child tree relationships
top / htopLive process monitor � useful for spotting high CPU processes
ls -la /proc/PID/exeResolve the executable path for a running process by PID
cat /proc/PID/cmdline | tr '\0' ' 'Full command line for a running process (even if renamed)
ls /proc/PID/fdOpen file descriptors for a process � network sockets, files
lsof -p PIDAll files and sockets opened by a specific process
lsof -i :PORTWhich process is listening on a specific port
kill -9 PIDForce-kill a process by PID
systemctl list-units --type=serviceAll systemd services and their status
systemctl status servicenameStatus, recent logs, and binary path of a service
journalctl -u servicenameFull systemd journal for a specific service

// Network Commands

CommandDescription
ss -tulpnAll listening TCP/UDP ports with process names � replacement for netstat
ss -anpAll active connections with PIDs
netstat -tulpnOlder equivalent of ss � still common on older systems
ip addrAll network interfaces and IP addresses
ip routeRouting table � look for unexpected routes
arp -aARP cache � IP to MAC mappings for recently contacted hosts
cat /etc/hostsLocal hostname resolution � check for redirected domains (malware persistence)
cat /etc/resolv.confDNS server configuration � check for rogue DNS server
ping -c 4 hostTest connectivity to a host
traceroute hostTrace path to host � identify routing anomalies
dig @8.8.8.8 domain.comDNS lookup using specific resolver � check against your DNS
tcpdump -i eth0 -w cap.pcapCapture live traffic to a file for analysis in Wireshark

// Log Analysis

Key log files

FileContents
/var/log/auth.logSSH logins, sudo usage, PAM events (Debian/Ubuntu)
/var/log/secureSame as auth.log for RHEL/CentOS
/var/log/syslogGeneral system messages � services starting, cron jobs, kernel messages
/var/log/messagesRHEL equivalent of syslog
/var/log/kern.logKernel messages � hardware errors, module loading
/var/log/cronCron job execution log
/var/log/apache2/access.logWeb server access log � look for exploitation attempts
/var/log/apache2/error.logWeb server error log
~/.bash_historyShell history per user � often tampered with by attackers

Log search commands

Bash
# Failed SSH logins
grep "Failed password" /var/log/auth.log | tail -50

# Successful SSH logins
grep "Accepted" /var/log/auth.log | tail -50

# Sudo commands run
grep "sudo:" /var/log/auth.log | grep "COMMAND"

# Login attempts by IP frequency
grep "Failed password" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -rn | head 20

# All cron jobs executed
grep "CRON" /var/log/syslog | tail -30

// File Investigation

CommandDescription
md5sum filenameMD5 hash of a file � compare against known good or threat intel
sha256sum filenameSHA-256 hash � preferred for threat intel lookups
strings filenameExtract printable strings from a binary � URLs, IPs, error messages
strings -a filename | grep -E "https?://"Extract URLs embedded in a file
xxd filename | head -20Hex dump � check magic bytes to identify file type
objdump -d binaryDisassemble a compiled binary
ldd binaryShared libraries a binary links against
strace -p PIDSystem calls made by a running process in real time
ltrace binaryLibrary calls � useful for malware behaviour analysis
readelf -h binaryELF header information � architecture, entry point, sections

// Persistence Hunting

These are the locations attackers commonly use to maintain persistence on Linux systems. Check all of these during an investigation.

Bash � Persistence locations to audit
# Cron jobs for all users
for user in $(cut -f1 -d: /etc/passwd); do crontab -l -u $user 2>/dev/null && echo "^ $user"; done

# System-wide cron
ls -la /etc/cron* /var/spool/cron/

# Systemd user services
find /etc/systemd /usr/lib/systemd ~/.config/systemd -name "*.service" 2>/dev/null | xargs ls -la

# SSH authorized keys (all users)
find / -name "authorized_keys" 2>/dev/null

# SUID binaries (custom or modified)
find / -perm -4000 -type f 2>/dev/null | sort

# World-writable directories
find / -xdev -type d -perm -0002 2>/dev/null | grep -v /proc

# Startup scripts
ls -la /etc/init.d/ /etc/rc.local /etc/profile.d/

# Aliases and shell config
grep -r "alias\|export\|source" /etc/profile /etc/bashrc /etc/bash.bashrc ~/.bashrc ~/.profile 2>/dev/null

// Investigation One-liners

Useful combinations for rapid triage during an incident.

Bash � Quick triage one-liners
# Who is logged in and what are they running?
w

# What processes have established outbound network connections right now?
ss -tnp state established

# Which process is listening on a suspicious port?
lsof -i :4444

# Files created in /tmp in the last hour
find /tmp -type f -mmin -60

# Check if bash history has been cleared (sign of cleanup)
wc -l ~/.bash_history

# Find files owned by root but world-writable
find / -user root -perm -o+w 2>/dev/null | grep -v /proc

# All users who have logged in recently
last | head -30

# What services are enabled at boot?
systemctl list-unit-files --state=enabled

# Check /proc for deleted-but-still-running binaries (malware indicator)
ls -la /proc/*/exe 2>/dev/null | grep deleted

Don't trust the tools on a compromised host. Rootkits can modify ps, ls, netstat, and other standard utilities to hide malware. On a suspected compromised system, boot from a trusted live environment or use tools from a read-only external drive, and rely on /proc directly where possible.