Home / Guides

Server guide

Disable SSH password login and use keys – step by step guide

This guide is for small‑business owners, agencies and hosting teams managing VPS, dedicated or cPanel servers. It shows why key‑based SSH is safer, how to switch securely, and how to maintain the configuration.

9 min readUpdated November 2026 by the RootManage teamWorks on Ubuntu, Debian, AlmaLinux and Rocky unless noted

The short answer

Disabling SSH password login forces users to authenticate with public‑private key pairs, eliminating brute‑force password attacks. Configure `sshd_config`, place authorized keys, test the new method, then turn off password authentication.

Why key‑based SSH matters

Using SSH keys instead of passwords raises the security level of remote access dramatically. A key pair consists of a public key stored on the server and a private key held by the user. Authentication succeeds only when the private key matches the public key, eliminating the need to transmit a secret over the network. Brute‑force tools that guess passwords cannot succeed against a correctly configured key, because there is no password to guess and the cryptographic challenge is far stronger than typical password entropy.

Key‑based authentication also simplifies account management and reduces the risk of credential reuse. When a user leaves, you can revoke access by removing a single public key from the authorized_keys file, without having to reset passwords on multiple systems. Keys can be protected with a passphrase, adding a second factor that protects the private key if it is ever copied. This layered approach makes it harder for attackers to gain persistent access, even if they obtain a copy of the key file.

  • Public keys are stored on the server; private keys never leave the client
  • Authentication is resistant to password‑spraying and dictionary attacks
  • Compromise of one key does not expose other accounts
  • Passphrase‑protected keys add an extra layer of protection
terminal
# Example: generate an RSA key pair (read before running)
ssh-keygen -t rsa -b 4096 -C "user@example.com"
# Add the public key to the server
ssh-copy-id -i ~/.ssh/id_rsa.pub user@server.example.com

After running the commands, you should see a new key pair in ~/.ssh and the public key added to the remote server's authorized_keys file. Verify that password authentication is disabled in /etc/ssh/sshd_config and that you can log in using the key without being prompted for a password.

Check current SSH authentication method

To understand how SSH is currently authenticating users, start by inspecting the SSH daemon configuration file. The file /etc/ssh/sshd_config contains directives that control password and key based logins. Look for the lines PasswordAuthentication and ChallengeResponseAuthentication. If either line is set to yes (or is missing, which defaults to yes on many distributions), password authentication is allowed. Conversely, a value of no indicates that passwords are not accepted for SSH sessions.

You can also query the active SSH daemon to see which authentication methods are enabled without editing the file directly. The command sshd -T | grep -i authentication prints the effective configuration after all includes and defaults are applied. This helps verify the live settings, especially after recent changes or when multiple configuration fragments are used. Always review the output before making any modifications.

  • Open /etc/ssh/sshd_config with a read‑only editor.
  • Search for PasswordAuthentication and note its value.
  • Run sshd -T | grep -i authentication to view effective settings.
  • Check for ChallengeResponseAuthentication as an additional password method.
  • Confirm that PubkeyAuthentication is set to yes to allow key logins.
terminal
grep -i '^PasswordAuthentication' /etc/ssh/sshd_config
sshd -T | grep -i authentication

If the output shows PasswordAuthentication no and ChallengeResponseAuthentication no, password login is disabled. Ensure PubkeyAuthentication yes is present, indicating that key‑based access is permitted.

Generate and distribute SSH key pairs

Each user should generate an SSH key pair on their own workstation. Use a modern algorithm such as Ed25519, which provides strong security with short keys and fast operations. Run the key generation command and, when prompted, choose a long passphrase to protect the private key. The passphrase adds a second factor of authentication, so even if the private key file is copied, an attacker cannot use it without the passphrase. Store the private key in the default location (~/.ssh/id_ed25519) and keep it readable only by the owner.

After the key pair is created, copy the public key (~/.ssh/id_ed25519.pub) to the remote server. Append the contents of the public key file to the user’s ~/.ssh/authorized_keys on the server, ensuring the file permissions are set to 600 and the .ssh directory to 700. Verify that the key line is on a single line with no extra spaces. Once the public key is in place, test the login to confirm that password authentication is no longer required for that user.

  • Use ssh-keygen -t ed25519 -a 100 for a strong key.
  • Protect the private key with a unique, long passphrase.
  • Never share the private key; only distribute the public key.
  • Set ~/.ssh directory to 700 and authorized_keys to 600 on the server.
  • Test the key‑based login before disabling password authentication.
terminal
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_ed25519 -C "your_email@example.com"
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@remote-server
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

After running the commands, you should be able to log in with ssh user@remote-server and be prompted only for the key passphrase. If the login succeeds without a password prompt, the public key is correctly installed and ready for password‑less access.

Configure the SSH daemon for key‑only access

Edit the SSH daemon configuration file to enforce key‑only authentication. Open /etc/ssh/sshd_config with a text editor, locate the line that starts with PasswordAuthentication and change its value to no. If the line is commented out, add PasswordAuthentication no on a new line. Also ensure PubkeyAuthentication yes is present and not commented. After saving, verify the file syntax with sshd -t before reloading the service. This prevents password logins while allowing public‑key access for users who have placed their authorized keys in ~/.ssh/authorized_keys.

While editing, consider disabling challenge‑response and empty passwords for extra safety. Set ChallengeResponseAuthentication no and PermitEmptyPasswords no if they are not already. Keep UsePAM yes unless you have a specific reason to disable it, as PAM handles account restrictions. Remember to create a backup of the original configuration file, for example by copying it to /etc/ssh/sshd_config.bak, before making changes. Once the daemon is reloaded, test a new SSH session using a key to confirm that password prompts no longer appear.

  • Backup the original config file before editing.
  • Set PasswordAuthentication no and PubkeyAuthentication yes.
  • Disable ChallengeResponseAuthentication and PermitEmptyPasswords.
  • Validate syntax with sshd -t.
  • Reload the daemon with systemctl reload sshd.
terminal
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sshd -t
systemctl reload sshd

After reloading, attempt to connect with a key‑based user. The login should succeed without a password prompt, and any attempt using a password should be rejected. Check the SSH log (/var/log/auth.log or /var/log/secure) for messages confirming that password authentication is disabled.

Test the new login method

Before you turn off password authentication, verify that your public‑key login works from a client that will be used for regular access. Open a terminal on a workstation, and run an SSH command that explicitly points to the private key you generated, for example ssh -i ~/.ssh/id_rsa user@your.server.com. If the connection succeeds and you are placed at the shell prompt without being asked for a password, the key pair is correctly installed on the server and the authorized_keys file is readable by the SSH daemon.

It is also a good idea to test the login with increased verbosity so you can see which authentication method is being used. Run ssh -vvv -i ~/.ssh/id_rsa user@your.server.com and look for lines that say “Offering public key” and “Authentication succeeded”. When you see those messages and no password prompt, you can be confident that the key works. Keep this session open while you prepare to modify the SSH configuration.

  • Use a separate test user if possible.
  • Check the SSH daemon logs (/var/log/auth.log or /var/log/secure).
  • Confirm the file permissions on ~/.ssh and authorized_keys are correct.
terminal
ssh -vvv -i ~/.ssh/id_rsa user@your.server.com

Successful output will end with a shell prompt and will show lines indicating public‑key authentication was offered and accepted. If you are still prompted for a password, review the key placement, permissions, and the SSH daemon’s AuthorizedKeysFile setting before disabling password logins.

What to avoid when disabling passwords

When you turn off password authentication, the first thing to check is that every legitimate user already has a working SSH key pair and that the public keys are correctly placed in their ~/.ssh/authorized_keys file. If a key is missing or malformed, the user will be unable to log in and may be locked out, especially if root login is also disabled. Always verify key permissions (600 for the file, 700 for the .ssh directory) and test a new session in a separate terminal before applying the change globally.

Another common mistake is leaving the root account accessible with a password or with an empty key file. Attackers often target root directly, so you should either disable root login entirely (PermitRootLogin no) or force root to use a key with PermitRootLogin prohibit-password. Forgetting to update firewall rules or failing to allow the alternative port can also block access. Take a snapshot or backup before editing /etc/ssh/sshd_config and reloading the service.

  • Do not edit the live SSH session; test in a new terminal first.
  • Never remove all keys before confirming at least one works.
  • Avoid setting PermitRootLogin yes after disabling passwords.
  • Do not forget to reload the SSH daemon safely.
  • Check that firewall rules still allow the SSH port.
terminal
ssh-keygen -t ed25519 -C "your_email@example.com"
mkdir -p ~/.ssh && chmod 700 ~/.ssh
cat id_ed25519.pub >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys
# Test a new login in another terminal before reloading
sudo systemctl reload sshd

After reloading, verify that you can connect using the key and that password prompts are no longer accepted. If the test fails, revert to the previous configuration from your backup or snapshot.

Maintain key‑only SSH over time

Regularly audit the list of authorized public keys on each server. Use a central inventory to track which keys belong to which users or services, and note the date each key was added. Schedule a monthly review to verify that every key is still required, and remove any that are no longer in use. Keeping this record helps you spot stale keys that could be exploited if the corresponding private key is compromised.

Plan a key rotation schedule, typically every 90‑180 days, depending on your risk profile. Generate a new key pair, distribute the new public key to the servers, and retire the old one after confirming successful login. Before making changes, take a snapshot or backup of the SSH configuration and the ~/.ssh/authorized_keys files so you can revert if access is lost. Document each rotation event in your inventory.

  • Enable SSH login alerts via syslog or a monitoring tool.
  • Use ssh-keygen -l -f to verify key fingerprints periodically.
  • Store encrypted backups of authorized_keys in a secure off‑site location.
  • Automate key expiration checks with a simple script.
  • Restrict key usage with from= or command= options when appropriate.
terminal
## Example: list keys with their addition dates (review before running)
awk '{print $3, $1}' /etc/ssh/sshd_config | grep AuthorizedKeysFile | cut -d'=' -f2 | while read f; do echo "File: $f"; ls -l "$f"; cat "$f"; done

The output should show each authorized_keys file, its modification time, and the keys it contains. Verify that the timestamps align with your rotation schedule and that no unexpected keys appear.

If you would rather have engineers do this for you, see Linux server management, Windows server management or emergency malware cleanup.

Questions people ask

How can I be sure my key works before disabling password login?

Test the key by opening a new terminal and connecting with `ssh -i /path/to/private user@host`. If the session succeeds without prompting for a password, the key works. Keep the original session open until you confirm the new login works, then you can safely disable password auth.

What should I do if I lose my private SSH key?

If you lose your private key, generate a new key pair on a trusted machine, add the new public key to the `~/.ssh/authorized_keys` file on each server, and remove the old public key entry. Also revoke any access that depended on the lost key.

Is it safe to allow root login with keys only?

Allowing root login with keys only is technically safe if the private key is protected with a strong passphrase and stored securely. However, many teams prefer disabling direct root SSH and using a regular user with `sudo` to reduce exposure and improve auditability.

How often should SSH keys be rotated and why?

Rotate SSH keys at least once a year or whenever a key is suspected of compromise. Regular rotation limits the window an attacker can use a stolen key and forces users to update credentials, maintaining a stronger overall security posture.

Want a person to look at it?

Tell us what you see. We reply with what we think is wrong and what it would take to fix it.