The clearest signs that a Linux server has been hacked are accounts or SSH keys you didn’t add, processes running from /tmp or from deleted files, CPU pinned at 100% by something you don’t recognise, unexplained outbound connections, and new cron jobs or systemd services. A non-empty /etc/ld.so.preload is another. If you find any of these, isolate the server and preserve evidence before you clean anything.

The checks below take about twenty minutes. One caveat first: on a compromised machine, the tools themselves (ps, ls, ss) can be tampered with, and a rootkit can hide from them. A clean result is reassuring, not proof.

1. Unknown users and SSH keys

Attackers like to add a way back in. Look for accounts and keys you can’t explain:

# Users with UID 0: should be root only
awk -F: '$3 == 0 {print $1}' /etc/passwd

# Accounts with a real login shell
getent passwd | awk -F: '$7 !~ /(nologin|false)$/ {print $1, $3, $6, $7}'

# Recently changed account files
ls -l --time-style=long-iso /etc/passwd /etc/shadow /etc/group /etc/sudoers
sudo ls -la /etc/sudoers.d/

# Every authorized_keys file, with fingerprints
sudo find / -xdev -name authorized_keys -type f 2>/dev/null | while read -r f; do
  echo "== $f"; sudo ssh-keygen -lf "$f"
done

A key with an unfamiliar comment, or a new authorized_keys file in a service account such as www-data or postgres, is a strong red flag.

2. Logins: last, lastb and the journal

last -a | head -30          # successful logins
sudo lastb -a | head -30    # failed logins (from /var/log/btmp)
lastlog | grep -v 'Never'   # last login per user
sudo journalctl _COMM=sshd --since "14 days ago" | grep 'Accepted'

Look for logins from countries or networks you don’t use, at odd hours, or for accounts that should never log in. On newer releases such as Debian 13, last comes from the wtmpdb package and lastlog has been replaced by lastlog2. The journal works everywhere.

3. Processes running from temp folders or deleted files

Malware often runs from world-writable directories, or deletes its own binary after it starts:

sudo ls -l /proc/*/exe 2>/dev/null | grep -E '/tmp/|/var/tmp/|/dev/shm/|\(deleted\)'

A process from /tmp or /dev/shm is almost never legitimate. A (deleted) binary can be harmless after a package upgrade (the old version is still running until it restarts). Check what it is:

sudo ls -l /proc/<PID>/exe /proc/<PID>/cwd
sudo tr '\0' ' ' < /proc/<PID>/cmdline; echo

Also look at the full process tree for anything odd, such as a shell started by the web server user:

ps -eo pid,ppid,user,etime,args --forest | less

4. CPU pinned by an unknown process

Crypto-miners are the most common payload on hacked servers, and they show up as constant high CPU:

ps -eo pid,user,%cpu,%mem,etime,args --sort=-%cpu | head -15
uptime

If the load is high but top shows nothing using CPU, something may be hiding from ps. We cover this in detail in our guide to detecting crypto-miners.

5. Unexpected outbound connections

sudo ss -tnp state established
sudo ss -tnp state established '( dport = :3333 or dport = :4444 or dport = :5555 )'

Check every remote address you can’t map to a known service (package mirrors, your database, APIs you call). Long-lived connections from a process with a strange name, or traffic to unusual high ports, deserve a closer look.

6. Modified system files

Compare installed files against the package database:

# Debian / Ubuntu
sudo dpkg --verify          # or: sudo apt install debsums && sudo debsums -c
# RHEL family
sudo rpm -Va | grep '^..5' | grep -v ' c '   # changed checksums, config files excluded

Changes to configuration files are normal. Changes to binaries in /usr/bin, /usr/sbin or /lib are not. Pay special attention to ssh, sshd, ps, ls, netstat, ss and top, which are common targets for replacement.

Look for files changed recently in system directories:

sudo find /etc /usr/bin /usr/sbin /usr/lib/systemd /etc/systemd -xdev -type f -mtime -7 -ls

7. Persistence: cron, systemd and ld.so.preload

Attackers make sure their code comes back after a reboot or a kill.

# Cron
sudo ls -la /etc/cron.d /etc/cron.hourly /etc/cron.daily /var/spool/cron/ 2>/dev/null
sudo cat /etc/crontab
for u in $(cut -d: -f1 /etc/passwd); do
  c=$(sudo crontab -l -u "$u" 2>/dev/null) && echo "== $u" && echo "$c"
done

# systemd services and timers
systemctl list-timers --all
systemctl list-unit-files --state=enabled --type=service
sudo find /etc/systemd/system /usr/lib/systemd/system -name '*.service' -mtime -30 -ls

# Library preload: normally this file does not exist or is empty
cat /etc/ld.so.preload 2>/dev/null

An entry in /etc/ld.so.preload loads a library into every process. Userland rootkits use it to hide files, processes and connections. If you find an unknown library there, treat the whole system as untrusted.

Also check shell start-up files (~/.bashrc, ~/.profile, /etc/profile.d/) and /etc/rc.local for commands that download or start something.

First response: what to do if you find something

Don’t start by deleting files. A careless clean-up destroys the evidence you need to find out how they got in, and the attacker usually has more than one way back.

  1. Isolate. Cut the server off from the network with your provider’s firewall or security group, and leave only your own IP for SSH (or use the provider’s console). Don’t shut down yet if you can avoid it, because memory and running processes are evidence.
  2. Preserve evidence. If your provider supports it, take a disk snapshot. Save volatile data to another machine:
# On the server
sudo sh -c 'ps auxwwf; ss -tanp; ss -ulpn; last -a; ls -l /proc/*/exe 2>/dev/null' \
  | sudo tee /root/ir-$(hostname)-$(date +%F).txt >/dev/null
sudo tar czf /root/logs-$(date +%F).tgz /var/log

# From your own machine (adjust user and paths)
scp 'root@server:/root/ir-*.txt' 'root@server:/root/logs-*.tgz' ./
  1. Rotate credentials from a clean machine. This means SSH keys, user passwords, database passwords, API keys and any secrets stored on the server. Remember the cloud and DNS accounts the server could reach, too.
  2. Find the root cause. Common entry points are weak SSH passwords, an outdated web application or plugin, an exposed Docker API, Redis or a database open to the internet, and leaked .env files.
  3. Rebuild, don’t repair. After a root-level compromise, reinstall from a known-good image, restore data from a backup taken before the intrusion, fix the root cause, then reconnect.
  4. Check your reporting obligations. Under the GDPR, a breach involving personal data must be reported to the supervisory authority within 72 hours of becoming aware of it, unless it is unlikely to result in a risk to people. Entities covered by NIS2 have their own deadlines for significant incidents. The ENISA website has guidance.

How Avanguard helps

  • Avanguard detects new users, new SSH keys, new open ports, changes to system files (/etc/passwd, sudoers, sshd_config) and scheduled tasks, programs running from temp folders or deleted files, crypto-miners, and library preload.
  • It checks the connections of the host and its containers against abuse.ch Feodo Tracker, abuse.ch SSL Blacklist and Spamhaus DROP.
  • The incident kit gives you a playbook by incident type, a timeline, evidence snapshots taken by the agent, and the NIS2, GDPR and DORA deadlines that apply to you. It is a technical aid, not a certification.

See server attack protection and compliance.

Summary

  • No unknown UID 0 users, login accounts, sudo rules or SSH keys
  • last, lastb and the journal show only logins you recognise
  • No processes running from /tmp, /var/tmp, /dev/shm or unexplained deleted binaries
  • No unknown process using the CPU, and no unexplained outbound connections
  • dpkg --verify or rpm -Va shows no modified binaries
  • Cron, systemd units, shell profiles and /etc/ld.so.preload are clean
  • If something is wrong: isolate, preserve evidence, rotate from a clean machine, rebuild, report