SSH is the front door of a production server. It is also the service attackers probe first, because a single working login hands over the whole machine. This ssh hardening checklist production servers can use in 2026 covers the settings that matter most: key-only login, no root access, a short list of allowed users, fail2ban, and a regular audit. None of these steps is hard on its own. The value is doing all of them, in order, and checking them again later instead of setting them once and forgetting them.
Work through the list on one server first, keep a second SSH session open while you change settings, and test a fresh login before you close the old session. Every step below tells you what to change, where the setting lives, and how to confirm it worked. If a step does not apply to your setup, note why and move on. A skipped step with a reason written down is fine.
First, map who can log in and from where
Before you touch the SSH config, list the people and systems that need access. Run grep -E ':/bin/(bash|sh)$' /etc/passwd to see accounts with a login shell, and check ls /home for user directories you may have forgotten. On many servers the list is longer than the owner expects: a former contractor, a deploy account from an old project, a monitoring user nobody uses any more. Every account on that list is a login path, so every account needs an owner and a reason to exist.
Next, look at who has actually logged in lately. Run sudo last -20 and sudo grep 'Accepted' /var/log/auth.log | tail -20 for accepted SSH logins and the addresses they came from. An address you do not recognize, or a login at an hour nobody works, is worth a question before you change anything. Write the map down in one place: each user, what they do on the server, and whether they still need access. That sheet becomes the basis for the allow list later in this checklist. Our guide to hardening a fresh Ubuntu server shows where the SSH steps sit next to firewall, updates, and user accounts.
SSH Hardening Checklist Production Servers: The 2026 Steps
Here is the whole list in one place. The sections after it explain the steps that need more than a line.
- Use key-only login. Turn off password authentication and challenge-response authentication.
- Turn off root login over SSH. Log in as a normal user and use sudo.
- Set an allow list with
AllowUsersso only named accounts can log in. - Use a non-default SSH port only as an extra layer, never as the only layer.
- Turn off X11 forwarding and agent forwarding unless a specific job needs them.
- Limit login attempts with fail2ban and a firewall rate limit.
- Keep OpenSSH updated and restart the service after config changes.
- Review users, keys, and logs every month and remove what is no longer needed.
Do the steps in this order because each one protects the next. Key-only login matters most, so it comes first. Root lockdown and the allow list come next because they shrink the target. Port changes, forwarding, and monitoring come after, because none of them helps much if passwords still work and root can still log in.
Keys done right: the part people skip
Switching to keys is the single biggest improvement on this list, and it is also the step where small mistakes cause the most lockouts. Generate keys with ssh-keygen -t ed25519 and protect the private key with a passphrase. Copy the public key to the server with ssh-copy-id user@server, then log in with the key once, in a new session, before you change any server setting. If the key login works, you are safe to turn passwords off. If it does not, fix the key first. Never disable passwords from inside your only working session.
On the server, edit /etc/ssh/sshd_config and set PasswordAuthentication no, ChallengeResponseAuthentication no, and PermitRootLogin no. Add AllowUsers deploy anna with your real usernames, space separated. To disable password authentication ssh setups rely on, those three lines plus a service restart are the core of it: run sudo sshd -t to check the config for errors, then sudo systemctl restart sshd. Test a fresh key login right away, then test that a password login fails.
One key per person, one key per device
Give each person their own key, and give each device its own key too. A shared key means a lost laptop forces everyone to rotate, and it means the logs can never tell you who logged in, only that someone with the shared key did. For ssh key only authentication to stay manageable, name keys clearly when you create them, for example with a comment flag like ssh-keygen -t ed25519 -C "anna-laptop-2026", and keep a list of which key belongs to which person and device. Private keys belong on the laptop of the person who uses them, never on the server and never in a shared chat message. When a laptop is lost or a team member leaves, remove their public key from ~/.ssh/authorized_keys on every server they could reach.
Fail2ban and monitoring: catching the attempts that get through
Even with passwords off, bots will keep knocking. Fail2ban watches the SSH log and bans addresses that fail too many times. Install it with sudo apt install fail2ban, then check the SSH jail with sudo fail2ban-client status sshd. The default settings ban an address after a handful of failed attempts, which is enough for most servers. If your logs show a flood from one network, tighten the ban time or the attempt limit in /etc/fail2ban/jail.local, but change one value at a time and watch the logs after each change.
A firewall rate limit adds the same protection one layer lower. UFW can limit SSH connections with sudo ufw limit ssh, and our UFW and fail2ban setup guide for Ubuntu shows how the two tools work together without conflicting rules. For the full SSH side, including custom ports, our walkthrough of key-only SSH login with custom ports and fail2ban covers the settings this checklist summarizes. Together they give you fail2ban ssh brute force protection that blocks repeat offenders before they can try enough passwords to matter. Monitoring closes the loop: check the fail2ban log weekly, or send its alerts somewhere you will see them. The basics in our Linux server monitoring basics cover log checks and alerts without asking you to run a full monitoring stack on day one.
What to do when something changes
Hardening is not a one time event. It breaks the moment a key is lost, a person leaves, or a new service needs access and someone opens a shortcut to get it working fast. Decide the response for each case now, while nothing is on fire.
When a private key is lost or a laptop is stolen, remove the matching public key from every server, then issue a new key pair. Do not wait to find out whether the lost key was used. When a team member leaves, remove their user account with sudo deluser --remove-home username or lock it with sudo usermod -L username if you need to keep their files for a while. When a contractor finishes, remove their key the same day the work ends, not at the next monthly review. When a new person needs access, add their key and their name to the AllowUsers line, test their login, and add them to the user map. The rule for all four cases is the same: access changes go through the map and the allow list together, so the two never drift apart.
A monthly audit that takes twenty minutes
Put a monthly repeat on your calendar and run the same five checks each time. First, list login shell accounts and compare them with the user map, removing anyone who should not be there. Second, read the authorized_keys file for each user and delete keys with no owner. Third, check sudo grep 'Failed password' /var/log/auth.log | wc -l for the month and look at whether the count jumped. Fourth, confirm the sshd settings are still what you set: password authentication off, root login off, allow list current. Fifth, apply pending OpenSSH and system updates, then restart the service and test a fresh login.
Write the results down in a short note: date, server, what you removed, what the failed login count was. Over a few months that note becomes a baseline, and a baseline is what turns a strange log line into a real signal instead of a guess. This ssh hardening checklist production servers follow is only as good as the last time someone ran it, and twenty minutes a month is a small price for a front door you can trust.