SSH hardening for a VPS, checked against 60 days of honeypot traffic
Our decoy server received 115,079 SSH connections in 60 days. Its address was never published, so none of them were aimed at us. They came from tools that try every address on the internet, and they would try yours the s
Our decoy server received 115,079 SSH connections in 60 days. Its address was never published, so none of them were aimed at us. They came from tools that try every address on the internet, and they would try yours the same way. Each setting below comes from something a bot actually did on the decoy, so you can see what it would have stopped.
Method in one line: one Echidra OSS sensor on a $6 VPS, one region, 28 July to 26 September 2026. The full numbers are in Sensor Report #1.
Root takes 85% of the guesses
There were 17,707 SSH login attempts, and root was the username in 15,114 of them. Stop root from logging in with a password:
PermitRootLogin prohibit-password
prohibit-password still lets root in with a key, if you need that. no is stricter.
Next come the accounts your image created
After root, the most-tried usernames were ubuntu (598), support (584) and admin (252), out of 614 different usernames. Bots try the accounts that cloud images and appliances create by default, because those are often left with weak or reused passwords.
Name the only accounts that may log in over SSH:
AllowUsers deploy
Every other username is refused, whatever password it sends.
Which passwords got in?
The decoy lets logins succeed so it can see what happens next. The sessions that mattered most got in with admin / admin and alexandra / 123. A real server with either of those would have been taken over the same way.
Turn passwords off completely and use keys:
PasswordAuthentication no
KbdInteractiveAuthentication no
The second line matters. On some systems, keyboard-interactive login still accepts a password when PasswordAuthentication is off.
A key planted in 2.5 seconds
On 10 August a bot logged in and, two and a half seconds later, typed one line:
mkdir -p /root/.ssh && echo 'ssh-rsa AAAAB3NzaC1yc2E...6oWL rsa-key-20250409' >> /root/.ssh/authorized_keys && chmod 700 /root/.ssh && chmod 600 /root/.ssh/authorized_keys
Its owner could now log back in without a password, even after the password was changed. Changing passwords after a break-in doesn't remove a key like this.
Find every authorized_keys file on the server and read each key's comment, the last field, to check you recognise it:
sudo find / -xdev -name 'authorized_keys*' -path '*/.ssh/*' 2>/dev/null \
| xargs -r sudo awk 'NF && !/^#/ {print FILENAME ": " $NF}'
To hear about the next change, watch the folder with auditd (on Debian or Ubuntu):
sudo apt install auditd
sudo install -d -m 700 /root/.ssh
echo '-w /root/.ssh/ -p wa -k ssh_keys' | sudo tee /etc/audit/rules.d/ssh-keys.rules
sudo augenrules --load
sudo ausearch -k ssh_keys then lists every write. Add a line for each user's ~/.ssh/ folder too.
Why the login is the line to hold
One bot that logged in sent a single long command. It:
- found whichever of
/tmp,/var/tmpor/dev/shmit could write to; - copied a script with
scp, using a private key it brought along; - if that failed, fetched the same script with
wgetorcurlover HTTPS and piped it intosh; - deleted the key and the script.
Another session read /bin/echo to learn the CPU type, the usual step before downloading malware built for it.
Every step had a fallback. Blocking one download tool or one folder won't stop a bot that's already logged in. That's why the three login settings above come first.
Cutting the noise from repeat offenders
One address made 17,417 connections to the decoy, and the ten busiest made 52.8% of all traffic. Most of the noise comes from a few sources, so limiting repeated failures removes a lot of it:
MaxAuthTries 3
On Debian or Ubuntu, fail2ban blocks an address for a while after too many failures:
sudo apt install fail2ban
sudo fail2ban-client status sshd
The second command should show the sshd jail. If it says the jail doesn't exist, enable it in /etc/fail2ban/jail.local. On systems without /var/log/auth.log, add backend = systemd to that jail.
This cuts log noise and load. It doesn't replace the login settings: a bot that guesses right on its first try is never blocked.
Everything in one file
On Ubuntu and Debian, put your settings in a file of their own. Files in /etc/ssh/sshd_config.d/ are read in name order and the first value wins. A name starting with 00- beats the 50-cloud-init.conf that some cloud images use to switch password login back on.
/etc/ssh/sshd_config.d/00-hardening.conf:
PermitRootLogin prohibit-password
PasswordAuthentication no
KbdInteractiveAuthentication no
MaxAuthTries 3
AllowUsers deploy
Replace deploy with your own username. Then:
- Make sure you can log in with your key before you turn passwords off.
- Check the file:
sudo sshd -t. No output means no errors. -
Check the values sshd will really use:
sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication|kbdinteractive|maxauthtries|allowusers'
4. Reload: sudo systemctl reload ssh. The service is called sshd on Fedora, RHEL and Arch.
5. Keep your current session open and log in from a second terminal. Close the first one only when the second works.
Which SSH setting do you change first on a new server? Tell us in the comments.
Method and limits
- One sensor, one region, one $6 VPS, from 28 July to 26 September 2026.
- A decoy only sees what reaches it. A server with a domain name or a public service would see more targeted traffic.
- Our own test traffic is excluded from every number.
- The sensor's address and provider aren't published.
See what's hitting your own server. Echidra OSS is open source (AGPL-3.0). It runs on a $6 VPS, records what bots try after they log in, and labels it with MITRE ATT&CK and a fix. Setup guide ยท Echidra OSS on GitHub. On GitHub, use Watch โ Releases to hear about new versions.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.