Skip to content

Disable SSH Password Authentication

Disable SSH password authentication

After configuring SSH key authentication, you can improve the security of your VPS by disabling password-based SSH login.

Once password authentication is disabled, users must authenticate using an authorized SSH private key. This significantly reduces the risk of brute-force attacks and password guessing.

Important

Before disabling password authentication, verify that you can successfully connect to your VPS using your SSH key. Keep your current SSH session open until you have confirmed that a second SSH session can authenticate using your key.

1

Confirm SSH key authentication

Before making any changes, verify that SSH key authentication is already working.

Connect to your VPS:

ssh username@your-server-ip

For example:

Do not continue until you have successfully connected using your SSH key.

2

Open the SSH configuration

Open the OpenSSH server configuration file:

sudo nano /etc/ssh/sshd_config
3

Disable password authentication

Locate the following directives:

PasswordAuthentication yes
KbdInteractiveAuthentication yes

If either directive is commented out with #, remove the # first.

Change them to:

PasswordAuthentication no
KbdInteractiveAuthentication no

Some operating systems may also include:

ChallengeResponseAuthentication yes

If present, change it to:

ChallengeResponseAuthentication no

Not every operating system or OpenSSH version includes ChallengeResponseAuthentication. If it is not present, simply skip it.

Leave the following setting enabled:

UsePAM yes

UsePAM should remain enabled. Disabling password authentication does not require disabling PAM.

Your configuration should now contain:

PasswordAuthentication no
KbdInteractiveAuthentication no
UsePAM yes

If your system includes ChallengeResponseAuthentication, it should also be configured as:

ChallengeResponseAuthentication no
4

Save the configuration

Save your changes in Nano:

  1. Press Ctrl + O.
  2. Press Enter.
  3. Press Ctrl + X.
5

Check for configuration overrides

Some operating systems or VPS images load additional SSH configuration files from:

/etc/ssh/sshd_config.d/

These files may take precedence over settings in the main configuration file.

Search every SSH configuration file for PasswordAuthentication:

sudo grep -RniE '^[[:space:]]*PasswordAuthentication' \
  /etc/ssh/sshd_config /etc/ssh/sshd_config.d/

If any additional file contains:

PasswordAuthentication yes

edit that file and change it to:

PasswordAuthentication no

Repeat the command until no active configuration file contains:

PasswordAuthentication yes

Configuration file location

The filename may differ depending on your operating system or VPS provider. Edit whichever file the command reports.

6

Validate the configuration

Check the SSH configuration for syntax errors:

sudo sshd -t

If no output is displayed, the configuration is valid.

If an error is reported, correct it before continuing.

7

Restart the SSH service

Restart the SSH service using the command for your operating system.

Ubuntu and Debian

sudo systemctl restart ssh

AlmaLinux, Rocky Linux, Oracle Linux and CentOS Stream

sudo systemctl restart sshd

FreeBSD

sudo service sshd restart
8

Verify the configuration

Display the effective SSH configuration:

sudo sshd -T | grep passwordauthentication

Expected output:

passwordauthentication no

Verify keyboard-interactive authentication:

sudo sshd -T | grep kbdinteractiveauthentication

Expected output:

kbdinteractiveauthentication no

If your system supports ChallengeResponseAuthentication, you can also verify it:

sudo sshd -T | grep challengeresponseauthentication

If passwordauthentication still reports yes, another configuration file is taking precedence over your setting. Return to the configuration override step and update every active file containing:

PasswordAuthentication yes
9

Test SSH key authentication

Keep your existing session open

DO NOT close your existing SSH session.

Open a second terminal and connect to your VPS:

ssh username@your-server-ip

To explicitly request SSH key authentication:

ssh -o PreferredAuthentications=publickey username@your-server-ip

If the connection succeeds, SSH key authentication is working correctly.

10

Verify password authentication is disabled

Open another terminal and force SSH to attempt password authentication only:

ssh -o PreferredAuthentications=password \
  -o PubkeyAuthentication=no \
  username@your-server-ip

Do not enter your password

PreferredAuthentications accepts an authentication method such as password or publickey. Do not enter your account password after this option.

When password authentication has been successfully disabled, the login should fail with a message similar to:

Permission denied (publickey).

This confirms that password-based SSH login is disabled.

Summary

Your VPS is now configured to reject password-based SSH logins while continuing to allow secure SSH key authentication.

The effective SSH configuration should include:

PasswordAuthentication no
KbdInteractiveAuthentication no
UsePAM yes

If your system includes ChallengeResponseAuthentication, it should also be configured as:

ChallengeResponseAuthentication no

Finally, verify the active configuration:

sudo sshd -T

This command displays the configuration currently used by the SSH server, including settings loaded from any additional configuration files.