Skip to content
Log In Sign Up info@muvcloud.com

Why Turn Passwords Off

A server reachable on the internet receives password guesses all day. With password authentication off, guessing is pointless: only someone holding a private key that is listed in authorized_keys can log in. The change takes a few minutes, but done in the wrong order it locks out you as well.

Before You Start

A mistake here can lock you out of the server. Follow this order:

  • Keep your current session open: do not log out until the last step works from a second terminal.
  • Key login first: a non-root user with sudo must already log in with a key. See ssh-copy-id and how to create a sudo user.
  • Test before reload: check the configuration with sudo sshd -t.
  • Know the way back: find the server console in your provider's control panel; it works without SSH.

Step 1: Confirm Key Login

From a second terminal, force key authentication and test sudo:

ssh -o PreferredAuthentications=publickey user@your_server_ip
sudo -v

If either step asks for something it should not, or fails, stop here and fix key login first.

Step 2: Find Where the Setting Lives

The SSH server reads /etc/ssh/sshd_config and the .conf files in /etc/ssh/sshd_config.d/. For most keywords, the first value sshd reads wins. On Ubuntu, Debian, AlmaLinux, and Rocky Linux the drop-in folder is included near the top of the main file, and the drop-ins are read in lexical order of their names, so a drop-in beats anything you write further down. Cloud images often ship one: cloud-init writes its SSH settings, including a possible PasswordAuthentication yes, to 50-cloud-init.conf in that folder. Look for every occurrence:

sudo grep -ri passwordauthentication /etc/ssh/sshd_config /etc/ssh/sshd_config.d/

Step 3: Turn Passwords Off

Create a drop-in whose name sorts first, so it is read before files such as 50-cloud-init.conf:

sudo nano /etc/ssh/sshd_config.d/00-disable-passwords.conf
PasswordAuthentication no
KbdInteractiveAuthentication no

The second line matters: with PAM, keyboard-interactive login can still ask for a password even when PasswordAuthentication is off, and its OpenSSH default is yes. Leave UsePAM as it is. If another drop-in sets PasswordAuthentication yes, change that line to no as well so the files do not contradict each other.

Step 4: Test the Configuration

sudo sshd -t
sudo sshd -T | grep -i passwordauthentication
sudo sshd -T | grep -i kbdinteractiveauthentication

sshd -t prints nothing when the files are valid. sshd -T prints the effective values; both should end in no.

Step 5: Reload SSH

A reload is enough; your open session stays connected.

SystemCommand
Ubuntu, Debiansudo systemctl reload ssh
AlmaLinux, Rocky Linuxsudo systemctl reload sshd

On recent Ubuntu releases SSH can be started on demand by ssh.socket; details are in how to restart the SSH service.

Step 6: Test from a Second Terminal

A key login must still work, and a password attempt must fail:

ssh user@your_server_ip
ssh -o PubkeyAuthentication=no user@your_server_ip

The second command should end with Permission denied (publickey). Only now close the old session.

If You Locked Yourself Out

Open the server console in your provider's control panel, log in there, delete or edit the drop-in file, run sudo sshd -t, and reload SSH again. The console does not use SSH, so these settings do not affect it. The next step many admins take is disabling root login over SSH.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations