# Read a full logcat /var/log/syslog# Last 50 lines (most recent activity)tail -50 /var/log/auth.log# Follow in real timetail -f /var/log/auth.log# First 20 lineshead -20 /var/log/syslog# Page through a large logless /var/log/syslog
# Search for a specific stringgrep "Failed password" /var/log/auth.log# Case-insensitive searchgrep -i "error" /var/log/syslog# Show lines around a match (context)grep -A 3 -B 3 "authentication failure" /var/log/auth.log# Filter by dategrep "May 20" /var/log/auth.log# Count occurrencesgrep "Failed password" /var/log/auth.log | wc -l
/var/log/auth.log (Debian/Ubuntu) or /var/log/secure (RHEL/CentOS) is the most valuable log for a pentester. It records every login attempt, sudo command, and session event.
cat /var/log/auth.log
What to look for:
# Successful SSH logins — who logged in and from wheregrep "Accepted" /var/log/auth.log# Feb 28 18:15:01 sshd[5678]: Accepted publickey for admin from 10.14.15.2 port 43210# Failed login attempts — brute force evidence, valid usernamesgrep "Failed password" /var/log/auth.log# Feb 28 15:04:22 sshd[3010]: Failed password for htb-student from 10.14.15.2 port 50223# Sudo commands run — what privileged actions were takengrep "sudo" /var/log/auth.log# Feb 28 18:15:03 sudo: admin : TTY=pts/1 ; PWD=/home/admin ; USER=root ; COMMAND=/bin/bash# New sessions createdgrep "session opened" /var/log/auth.log# su usage — user switchinggrep "session opened for user" /var/log/auth.log
Pentest intel from auth.log:
# All unique IPs that attempted to log ingrep "Failed password\|Accepted" /var/log/auth.log | grep -oE "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" | sort -u# All usernames that were attempted (valid + invalid)grep "Failed password" /var/log/auth.log | awk '{print $9}' | sort | uniq -c | sort -rn# All commands run via sudogrep "COMMAND" /var/log/auth.log | awk -F"COMMAND=" '{print $2}' | sort -u
# Credentials passed in GET parameters (bad practice but it happens)grep -E "password=|passwd=|pass=|token=|key=|secret=" /var/log/apache2/access.log# POST data isn't logged by default, but errors sometimes expose itgrep -i "password\|credential" /var/log/apache2/error.log# User agents — identify tools used against this serverawk '{print $12}' /var/log/apache2/access.log | sort | uniq -c | sort -rn | head -20# Most active IPsawk '{print $1}' /var/log/apache2/access.log | sort | uniq -c | sort -rn | head -20
On modern systems, many logs go to the systemd journal instead of flat files.
# All logs (most recent first)journalctl -r# Logs for a specific servicejournalctl -u ssh.servicejournalctl -u apache2.servicejournalctl -u cron.service# Logs since last bootjournalctl -b# Logs from a specific time windowjournalctl --since "2024-01-01 00:00" --until "2024-01-01 23:59"# Follow in real timejournalctl -f# Show only errorsjournalctl -p err# Without pager (pipe-friendly)journalctl -u ssh --no-pager | grep "Accepted"
# Timeline of all auth events for a specific usergrep "htb-student" /var/log/auth.log | sort# What commands did admin run via sudo today?grep "sudo.*admin\|admin.*sudo" /var/log/auth.log | grep "COMMAND"# What connected to this machine in the last hour?grep "Accepted\|Failed" /var/log/auth.log | tail -100# What services restarted recently?grep "Started\|Stopped" /var/log/syslog | tail -30# Any privilege escalation attempts?grep "su\[" /var/log/auth.loggrep "sudo" /var/log/auth.log | grep -v "session\|pam"