Home / Guides

Server guide

How to recognise if your Linux server has been compromised

This article is for VPS, dedicated and cPanel administrators who suspect a breach. It shows the key indicators, verification methods, and immediate actions to secure the server.

8 min readUpdated November 2026 by the RootManage teamWorks on Ubuntu, Debian, AlmaLinux and Rocky unless noted

The short answer

A hacked Linux server typically shows unexpected user accounts, unexplained processes, altered system files, and abnormal network traffic. Spotting these signs early lets you contain the intrusion and begin remediation.

Why detecting a breach matters

When a breach goes unnoticed, attackers can harvest sensitive data such as customer records, credentials, and intellectual property. This exposure can lead to regulatory penalties, loss of client trust, and costly legal actions. Even if the data is not immediately stolen, the presence of a backdoor or malicious script can be used later to exfiltrate information, making the impact grow over time. The longer the compromise remains hidden, the harder it becomes to contain and remediate, increasing overall risk to the business.

An undetected intrusion also threatens service continuity. Malicious processes may consume CPU, memory, or disk I/O, causing slowdowns or outages that affect user experience. Attackers might alter configuration files, disable security controls, or launch denial‑of‑service attacks against your own customers. Reputation damage follows when clients experience downtime or discover their data was at risk, potentially driving them to competitors and harming revenue streams.

  • Data loss or theft
  • Regulatory non‑compliance penalties
  • Service slowdown or outage
  • Damage to brand reputation
  • Increased remediation costs
terminal
# Example: view recent authentication attempts
journalctl -u sshd --since "24 hours ago" | grep 'Failed password'
# Example: list recently modified binaries
find /usr/local/bin -type f -mtime -1 -exec ls -l {} \;

The command output will show any recent failed SSH logins and binaries that were modified in the last day. Look for repeated failed attempts from unknown IPs or unexpected changes to executables, which may indicate an ongoing compromise.

Common indicators of compromise

When a Linux server is compromised, the signs are often subtle but can be spotted with regular monitoring. Look for user accounts that you did not create, especially ones with UID 0 or sudo privileges. Unexpected services listening on ports, or processes running under unknown names, may indicate a backdoor. Review authentication logs for repeated failed logins followed by a successful one from unfamiliar IP addresses. Sudden changes in file timestamps, especially in system directories, can also be a red flag that an attacker has altered binaries or scripts.

Resource usage anomalies are another common indicator. A spike in CPU, memory, or disk I/O without a corresponding workload could mean malicious mining, spamming, or data exfiltration scripts are running. Network traffic that spikes or shows connections to unusual remote hosts should be investigated. Additionally, watch for log entries that contain strange characters, repeated error messages, or entries that do not match normal application behavior. These symptoms together often point to a compromise and warrant immediate investigation.

  • Unknown user accounts or groups appear in /etc/passwd or /etc/group
  • New services listening on unexpected ports (check with netstat or ss)
  • Log files contain strange entries or repeated authentication failures from unknown IPs
  • Unexplained spikes in CPU, memory, or disk usage
terminal
# Example: List users with UID 0 (root) and any other accounts with UID 0
awk -F: '($3==0){print $1}' /etc/passwd
# Example: Show listening network services
ss -tulnp
# Example: Find recent changes in /usr/bin (last 2 days)
find /usr/bin -type f -mtime -2 -ls

Run the example commands in a safe environment or after taking a snapshot. Look for any output that shows unfamiliar usernames, services, or recently modified binaries, and investigate those findings further.

Checking system logs and audit trails

Start by checking the authentication logs. On most distributions the file is /var/log/auth.log or /var/log/secure. Look for repeated failed login attempts, logins from unfamiliar IP addresses, or successful logins at odd hours. Use grep to filter for keywords such as Failed, Invalid, or session opened and note any patterns that don’t match normal user activity.

Next, examine sudo usage and the systemd journal. The sudo log is typically part of the auth log, but you can also query it directly with journalctl _COMM=sudo. Look for commands run with sudo that you did not initiate, especially those involving user management, service restarts, or file modifications. The systemd journal (journalctl -xe) can reveal kernel messages, service crashes, or unexpected daemon starts that may indicate a breach.

  • Search auth logs for repeated failures or unknown IPs
  • Filter sudo entries with journalctl _COMM=sudo
  • Review journalctl -xe for abnormal service activity
  • Check for new user accounts in /etc/passwd
terminal
# Example commands (review before running)
grep -i 'failed\|invalid' /var/log/auth.log
journalctl _COMM=sudo --no-pager
journalctl -xe --no-pager

The output should show only legitimate login attempts and sudo usage. Any unknown IP addresses, unexpected sudo commands, or unexplained service restarts are signs to investigate further.

Inspecting running processes and network connections

Start by listing all active processes and comparing them to the services you expect on the server. Use tools like ps and top to view the command line, user, and resource usage for each process. Look for processes running under unexpected users, with odd names, or consuming unusual CPU or memory. If you see a process that you cannot identify, note its PID, executable path, and start time for further investigation.

Next, examine network activity to spot suspicious open ports and outbound connections. Commands such as ss -tulnp and netstat -plant reveal which services are listening and which remote addresses are connected. Pay attention to ports that are not part of your normal web, mail, or database stack, and to connections to unknown IP ranges. Unexpected listeners or frequent outbound traffic can indicate a compromised component.

  • Run ps aux --sort=-%cpu to see top CPU‑intensive processes.
  • Use ss -tulnp to list listening sockets with owning process IDs.
  • Check outbound connections with ss -tp or netstat -plant.
  • Verify the executable path of a suspicious PID with readlink -f /proc/<PID>/exe.
terminal
ps aux --sort=-%cpu
ss -tulnp
ss -tp
readlink -f /proc/$(pidof suspicious_process)/exe

In the output, look for process names you do not recognize, services listening on non‑standard ports, and connections to IP addresses that are not part of your infrastructure. Any such anomalies should be logged and examined further before taking remediation steps.

Verifying file integrity and configuration changes

To check whether critical files have been altered, start by generating known good checksums for system binaries, configuration files, and scripts. Store these values in a secure location, such as an offline backup or a read‑only directory. Later, run a checksum utility like sha256sum or md5sum on the same files and compare the output with the stored values. Any mismatch indicates that the file's contents differ from the trusted baseline, which could be a sign of tampering or malicious replacement.

Package managers can also verify the integrity of installed software. On Debian‑based systems, dpkg -V will report files that differ from the package metadata, while on RPM‑based distributions, rpm -Va performs a similar audit. Additionally, use diff or git diff against version‑controlled configuration directories to spot unauthorized changes. Regularly running these checks helps you quickly identify unexpected modifications before they lead to larger compromises.

  • Create and store baseline checksums for critical files.
  • Run dpkg -V or rpm -Va to verify package integrity.
  • Use diff or a version control system to compare config files.
  • Automate periodic integrity scans with cron jobs.
terminal
sha256sum /usr/sbin/sshd > /root/sshd.sha256
sha256sum -c /root/sshd.sha256
# For Debian/Ubuntu
sudo dpkg -V | grep '^..5'
# For RHEL/CentOS
sudo rpm -Va | grep '^..5'

Look for lines marked as changed, missing, or having unexpected permissions. Any reported differences should be investigated by reviewing the file's purpose, checking logs for recent edits, and restoring a known good version from backup if necessary.

Immediate remediation steps

First isolate the affected host to stop any further damage. Disable inbound traffic by moving the server into a quarantine network segment or by applying a temporary firewall rule that only allows SSH from a trusted IP. Once isolated, take a snapshot or create a full disk image for forensic analysis. Do not reboot the system until you have captured the current state. This preserves volatile evidence such as running processes, network connections, and memory contents that may be needed later.

After isolation, rotate all credentials. Change passwords for root, sudo users, and any service accounts. Regenerate SSH keys and update authorized_keys files. Review and revoke any unknown keys. Finally, restore the server from a known‑good backup taken before the compromise. Verify the backup integrity, apply the latest patches, and test the restored system in a separate environment before returning it to production.

  • Create a read‑only snapshot or disk image for analysis.
  • Block external traffic with a temporary firewall rule.
  • Change all passwords and regenerate SSH keys.
  • Remove unknown user accounts and SSH keys.
  • Restore from a clean backup after patching.
terminal
## Example commands (review before execution)
# Take a snapshot (replace <vm-id> and <snapshot-name>)
virsh snapshot-create-as <vm-id> <snapshot-name> --atomic
# Add a temporary firewall rule to allow only your IP (replace <your-ip>)
iptables -I INPUT -s <your-ip> -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j DROP

When the commands complete, verify that the firewall now only permits SSH from your trusted IP and that the snapshot appears in your virtualization manager. Confirm that all password changes have taken effect by logging in with the new credentials. A successful restore will show the server running the expected services without any unknown processes or files.

Preventing future intrusions

To reduce the attack surface, start by disabling or removing services you do not use, such as FTP, Telnet, or legacy web servers. Use strong, unique passwords and enable two‑factor authentication for all privileged accounts. Configure SSH to use key‑based logins only, change the default port, and set "PermitRootLogin no". Apply the principle of least privilege: create separate users for each application, assign only the permissions required, and use sudo for administrative tasks. Regularly audit file permissions and ensure critical binaries are owned by root and not writable by others.

Continuous monitoring is essential. Install a host‑based intrusion detection system like AIDE or OSSEC and schedule daily integrity checks. Enable and review system logs with tools such as journalctl or logwatch, looking for repeated failed logins, unusual command execution, or unexpected network connections. Set up automated alerts for kernel panics, package updates, or configuration changes. Keep a snapshot or backup before any major change, and test restoration procedures periodically to ensure you can recover quickly if an intrusion occurs.

  • Disable unused daemons and close their ports
  • Enforce key‑based SSH authentication and disable password logins
  • Run regular package updates and apply security patches promptly
  • Deploy a host‑based IDS and schedule daily integrity scans
  • Rotate logs and retain them for at least 30 days
terminal
# Example: install and initialise AIDE for file integrity monitoring
sudo apt-get update && sudo apt-get install -y aide
sudo aideinit   # creates the initial database; read the output before proceeding
sudo cp /var/lib/aide/aide.db.new /var/lib/aide/aide.db
# Schedule daily checks via cron (edit with crontab -e)
0 3 * * * /usr/bin/aide --check > /var/log/aide/check.log 2>&1

After implementing these steps, you should see a reduced number of open ports, fewer failed login attempts in your logs, and regular integrity check reports from AIDE. Any new alerts or unexpected changes indicate areas that still need attention.

If you would rather have engineers do this for you, see Linux server management, Windows server management or emergency malware cleanup.

Questions people ask

What log entries indicate a possible brute‑force attack?

Look for repeated failed login attempts in `/var/log/auth.log` or `/var/log/secure`. Entries showing “Failed password” or “Invalid user” from many different IPs within a short period suggest a brute‑force attempt. Also watch for “Connection closed by” messages after many failures.

How can I tell if a rootkit is hidden on my system?

Detecting a hidden rootkit involves checking for anomalies: unexpected files in `/dev`, mismatched checksums of system binaries, unknown kernel modules listed by `lsmod`, and altered system call tables. Use tools like `rkhunter` or `chkrootkit` and compare binaries against known good packages.

What is the safest way to reset compromised SSH keys?

First, back up current `~/.ssh/authorized_keys` and any host key files. Then generate a new key pair with `ssh-keygen`, replace the old public keys on all client machines, and update the server’s `authorized_keys`. Finally, restart the SSH service and verify access with the new keys.

Which monitoring tools are best for early detection of Linux breaches?

For early breach detection, use `auditd` to log system calls, `fail2ban` to block repeated failures, and `OSSEC` or `Wazuh` for host‑based intrusion detection. Complement these with `Logwatch` or `journalctl` alerts and a central log aggregator like `ELK` or `Graylog`.

Want a person to look at it?

Tell us what you see. We reply with what we think is wrong and what it would take to fix it.