It’s quite easy to disable the password based login in the SSH. Before you proceed check if you have prepared the system to logon without password.
- You have a user other than root, who can enter the remote server. If not, take a look into my article How to disable root login
- Please check if that user has sufficient permissions if you use an existing user. # usermod -aG sudo user
- You have created an ssh key on your local machine and shared the key with the remote server. If not, take a look into my article Configure SSH login without password
Now, no prompt is asking you for a password, but you are still able to do it. You can test it by using the following command for login:
# ssh user@servername -o PubkeyAuthentication=no
To disable the password log in at all you need to edit the following file:
# sudo editor /etc/ssh/sshd_config
Find the property and change the value
PasswordAuthentication no
The last step is to restart the ssh service and your change will take action with the following command:
# sudo systemctl reload ssh
If you try to login with the option -o PubkeyAuthentication=no you’re not allowed to do this.
# user@servername: Permission denied (publickey).