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.
Confirm SSH key authentication
Before making any changes, verify that SSH key authentication is already working.
Connect to your VPS:
For example:
Do not continue until you have successfully connected using your SSH key.
Disable password authentication
Locate the following directives:
If either directive is commented out with #, remove the # first.
Change them to:
Some operating systems may also include:
If present, change it to:
Not every operating system or OpenSSH version includes ChallengeResponseAuthentication. If it is not present, simply skip it.
Leave the following setting enabled:
UsePAM should remain enabled. Disabling password authentication does not require disabling PAM.
Your configuration should now contain:
If your system includes ChallengeResponseAuthentication, it should also be configured as:
Save the configuration
Save your changes in Nano:
- Press Ctrl + O.
- Press Enter.
- Press Ctrl + X.
Check for configuration overrides
Some operating systems or VPS images load additional SSH configuration files from:
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:
edit that file and change it to:
Repeat the command until no active configuration file contains:
Configuration file location
The filename may differ depending on your operating system or VPS provider. Edit whichever file the command reports.
Verify the configuration
Display the effective SSH configuration:
Expected output:
Verify keyboard-interactive authentication:
Expected output:
If your system supports ChallengeResponseAuthentication, you can also verify it:
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:
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:
To explicitly request SSH key authentication:
If the connection succeeds, SSH key authentication is working correctly.
Verify password authentication is disabled
Open another terminal and force SSH to attempt password authentication only:
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:
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:
If your system includes ChallengeResponseAuthentication, it should also be configured as:
Finally, verify the active configuration:
This command displays the configuration currently used by the SSH server, including settings loaded from any additional configuration files.