How to secure SSH on a Linux server
SSH is the front door to your server. These steps stop the password brute-forcing that fills every server's logs and close the most common way in.
Steps
- Add your public key: ssh-copy-id user@server, and confirm you can log in with the key.
- In /etc/ssh/sshd_config set PasswordAuthentication no, PermitRootLogin no and PubkeyAuthentication yes.
- Optionally restrict users with AllowUsers, and keep the default port unless you have a reason to change it.
- Reload: sudo systemctl reload sshd (keep your current session open until you've tested a new one).
How to verify
- From another terminal, ssh user@server should work with your key and refuse a password.
- ssh -o PubkeyAuthentication=no user@server should be rejected.
FAQ
- Does changing the SSH port help?
- Only a little — it cuts noisy scanning but isn't real security. Key-only auth and no root login are what matter.
Have SkyShield check this for you
SkyShield finds this across every server and cloud account and shows the fix in plain words. Free for one server, then from $49 per server a month. Start free.