To disable password authentication for SSH on Linux, follow these steps:
- Open the SSH configuration file:
sudo nano /etc/ssh/sshd_config
- Find the line that says:
PasswordAuthentication yes
- Uncomment the line by removing the
#
character and changeyes
tono
. It should look like this:PasswordAuthentication no
- Save the file and exit the editor.
- Restart the SSH daemon to apply the changes:
sudo systemctl restart ssh
Now, users will only be able to log in using a private key, which is much more secure than using a password.
Note: Before disabling password authentication, make sure you have a way to log into the server using a private key. If you lock yourself out, you’ll need to have physical access to the machine or another means of access, such as a rescue mode, to regain access.