Exclusive Metin2 game shield on FreeBSD: Automatic siege mode, VIP list, and whitelist from your dashboard. See how it works
Create a server

Guide

How to Check If Your VPS Has Been Compromised

CPU usage that no one can explain, a spam abuse warning, or an SSH key you don't recognize are all good reasons to check the server. This check follows the typical sequence of actions taken by an intruder: they gain access, execute something, and ensure they can return.

Before You Begin

  • Don't restart or delete anything yet: you'll lose processes in memory and clues in the logs.
  • Make a note of each finding, including the time and the command that displayed it. If you reinstall later, that list will tell you which credentials to change.
  • If the system binaries have been tampered with, ps or ss might be hiding something; step 4 checks for this.

1. Who is logged in?

last -aiF | head -n 20sudo lastb -aiF | head -n 20sudo journalctl -u ssh --since "7 days ago" | grep -E "Accepted|session opened"

Look for logins from IP addresses that aren't yours, at times when you weren't working, or using accounts you don't use. A Accepted password on a server where you only log in with SSH keys—without a password—is a clear red flag. On Debian and Ubuntu, the service is called ssh; on Rocky Linux or AlmaLinux, it's sshd.

2. What is running right now?

ps aux --sort=-%cpu | head -n 20sudo ss -tulpnsudo ss -tnp state established

Be wary of processes with names that mimic those of the kernel or the system, of binaries running from /tmp, /var/tmp, or /dev/shm, and of persistent outbound connections to unusual ports—as cryptocurrency miners do with their pools. To see where a suspicious process is coming from, replace PID with its number:

sudo ls -l /proc/PID/exesudo cat /proc/PID/cmdline | tr '\0' ' '

3. How does the intruder ensure that he can return?

Persistence is what turns a one-time intrusion into a permanent one. Review the four most commonly used mechanisms.

Scheduled Tasks

for u in $(cut -d: -f1 /etc/passwd); do sudo crontab -l -u "$u" 2>/dev/null | sed "s/^/$u: /"; donels -la /etc/cron.d /etc/cron.hourly /etc/cron.dailysystemctl list-timers --all

systemd Services

systemctl list-unit-files --type=service --state=enabledls -lt /etc/systemd/system | head -n 15

Authorized SSH keys

sudo cat /root/.ssh/authorized_keyssudo sh -c 'cat /home/*/.ssh/authorized_keys'

Users with privileges

awk -F: '$3 == 0 {print $1}' /etc/passwdgetent group sudo

Only root should have UID 0. Any other user with UID 0, or a member of the sudo group that you did not create, is a serious issue. In RHEL-based distributions, the equivalent group is wheel.

4. Have any system files been modified?

In Debian and Ubuntu, debsums compares each installed file with its package's checksum and displays only those that do not match:

sudo apt install -y debsumssudo debsums -s

In Rocky Linux or AlmaLinux, the equivalent is rpm -Va. A change in /usr/bin/ps, /usr/bin/ss, or /usr/sbin/sshd indicates a rootkit, and from that point on, you can't trust anything the system displays. Also check for hidden executables in the temporary folders:

sudo find /tmp /var/tmp /dev/shm -type f -perm -u+x -ls

If you confirm the intrusion

  1. Block access: Limit SSH to your admin IP and stop malicious processes.
  2. From another device, change all passwords and access keys associated with that server: databases, APIs, deployment tokens, and email accounts.
  3. Copy only data (database exports, files uploaded by users); never copy binaries or scripts that you cannot review line by line.
  4. Reinstall the system from scratch and restore the verified data. Manually cleaning a server infected with a rootkit offers no guarantee.
  5. Find out how they got in (weak password, outdated plugin, exposed control panel) before putting it back online.

ext step

Time to reinstall? Deploy a clean Cloud VPS and migrate the verified data to it while the old server remains isolated.

Related guides