SSH is by default configured to allow logins via both password and public key.

Specifies whether password authentication is allowed. The default is yes.

Users would choose bad passwords and might not manage their passwords properly. This could be a security risk thus you might want to disable password authentication on your SSH servers. The alternative is to configure public key authentication for your users.

You can enable or disable password authentication by configuring PasswordAuthentication directive for your SSH server.

Steps to enable or disable password authentication in SSH:

  1. Launch your preferred terminal application.
  2. Open sshd configuration file using favourite text editor.
    $ sudo vi /etc/ssh/sshd_config
    [sudo] password for user:
  3. 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 the # at the beginning of the line if exists.

    Make sure other authentication method is enabled and tested before disabling password authentication method.

  4. 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
Discuss the article:

Comment anonymously. Login not required.