Disclaimer:
use this code at your own risk and only if you know what you are doing. no liability from us for the consequences. so leave us alone if things go sideways
Sometimes you feel the need of adding an extra layer of security to your server. You can disable the password authentication for SSH on your server. Feel free to do so if you know what you are up to. I strongly recommend that during this whole operation you have a user logged into the remote machine who has a sudo credentials, just in case something goes sideways 😉
Step 1 log into the server
ssh user@remote-server
Step 2 edit the ssh config file /etc/ssh/sshd_config and change these settings, after the save restart the ssh service
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no
Step 3 restart the ssh service (depends on your system)
sudo systemctl restart ssh
sudo sudo systemctl restart sshd
Thats all folks !
This blog post can be used with this article 4-step-setup-ssh-login-without-password