How to enable or disable password authentication in SSH
SSH server's default configuration is to allow both password and public key logins.
PasswordAuthentication
Specifies whether password authentication is allowed. The default is yes.
Some admins consider password login to be insecure due to improper password management by the users. As such, you might want to disable password authentication on your SSH servers and force users to authenticate using other methods such as the public key.
You can enable or disable password authentication by configuring PasswordAuthentication directive in your SSH server.
Steps to enable or disable password login in SSH:
-
Launch your preferred terminal application.
-
Open sshd configuration file using favourite text editor.
$ sudo vi /etc/ssh/sshd_config [sudo] password for user:
-
Search for PasswordAuthentication and set the option to no to disable PasswordAuthentication method and yes to enable.
PasswordAuthentication no
Add the line if it doesn't already exist and remove # at the beginning of the line if it exists.
Set it to yes to allow password authentication method and no to disallow.Make sure another authentication method is enabled and tested before disabling the password authentication method.
-
Reload or restart SSH server service.
$ sudo systemctl restart sshd
Guide compatibility:
Operating System |
---|
Ubuntu Linux |
Debian Linux |
Red Hat Enterprise Linux |
Fedora Linux |
CentOS Linux |
openSUSE Linux |
SUSE Linux Enterprise Server |
FreeBSD |
OpenBSD |
NetBSD |
macOS |