Think your Linux server was hacked? Seven quick checks on Ubuntu and Debian
Notice sudden CPU usage at 100%, strange outgoing traffic alerts from your hosting provider, or unfamiliar files on disk? Before wiping anything or guessing, run these seven non-destructive SSH checks to see if someone is inside your server.
1. Check recent logins and sudo history
Look for successful SSH logins from unfamiliar IP addresses or strange login times:
last -aiF | head -n 30
sudo grep -E "Accepted|sudo:" /var/log/auth.log | tail -n 40
For a deeper look at SSH and admin actions, see checking who logged in and sudo history on Ubuntu and Debian.
2. Check authorized_keys on every user account
Attackers almost always drop an extra SSH public key so they can return cleanly even after you change passwords:
sudo cat /root/.ssh/authorized_keys 2>/dev/null
sudo find /home -name authorized_keys -exec head -n 20 {} +
Make sure you recognize every key line. Also ensure SSH keys are set up and password login is off.
3. Check for unknown users or UID 0 accounts
Only root should ever have UID 0. Check for added accounts or unexpected sudoers:
awk -F: '$3==0 {print $1}' /etc/passwd
awk -F: '$3>=1000 {print $1 ":" $3 ":" $7}' /etc/passwd
4. Check high-CPU processes and deleted binaries
Crypto-miners and malware often run from /tmp or /dev/shm, or keep running after deleting their file on disk:
ps aux --sort=-%cpu | head -n 15
sudo ls -l /proc/*/exe 2>/dev/null | grep -E "\(deleted\)|/tmp|/dev/shm"
5. Check unexpected listening or outbound connections
See every process holding a port open or connecting out to an unfamiliar remote IP:
sudo ss -tulpn
sudo ss -tnp state established
Compare against what you expect in how to check open ports on Ubuntu and Debian.
6. Inspect cron jobs and systemd timers
Persistence mechanisms reinstall malware minutes after you kill it unless you remove scheduled tasks too:
sudo ls -la /etc/cron.d /etc/cron.daily /var/spool/cron/crontabs
systemctl list-timers --all --no-pager
7. Scan websites with ClamAV and inspect recent file edits
If your PHP website hosts the entry point, inspect files modified in the last 7 days and run our guide to scan your PHP site with ClamAV. If you confirm a compromise, stop and follow our first steps for a hacked PHP site — clean backups onto a fresh server are almost always safer than trying to hand-clean a rooted OS.
If you want an independent manual penetration test or server hardening check after recovery, SecurityNest offers fixed-price Linux and web application security testing.