Disable SSH password login on a server

Once your key works, close the door the bots keep knocking on.

SNP 070 #15A Filed cmd ssh linux

First make sure your key login works, in a second terminal, while the first one stays open. Then edit /etc/ssh/sshd_config:

shell
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password

On Ubuntu there may be a file in /etc/ssh/sshd_config.d/ that sets PasswordAuthentication yes and overrides you. Check what is in effect with:

shell
sudo sshd -T | grep -i passwordauthentication

Then reload and test from yet another terminal:

shell
sudo systemctl reload ssh

If ssh -o PubkeyAuthentication=no user@server gets refused, you're done.