security.frabs.net
All Guides

Logins · about 10 minutes

Turn Off SSH Password Logins

What This Means

SSH accepts passwords, so every bot on the internet can keep guessing them.

Why It Matters

An SSH key can't be guessed. Once keys are the only way in, password-guessing attacks stop mattering.

Before you start

Do step 1 first and check your key works. If you turn passwords off without a working key, you lock yourself out.

  1. 1

    Make sure your key works

    On your own computer, create a key if you don't have one (ssh-keygen -t ed25519) and copy it to the server with ssh-copy-id root@your-server. Then check the server has it:

    ls -l ~/.ssh/authorized_keys
    Terminal: Make sure your key works, on Ubuntu 24.04
  2. 2

    See the current setting

    sshd -T | grep -iE '^(passwordauthentication|kbdinteractiveauthentication)'
    Terminal: See the current setting, on Ubuntu 24.04
  3. 3

    Turn passwords off

    Settings in /etc/ssh/sshd_config.d/ are read first, and the first value SSH reads wins, so a file named 10-… beats the defaults and anything your host added (such as 50-cloud-init.conf).

    printf 'PasswordAuthentication no\nKbdInteractiveAuthentication no\n' > /etc/ssh/sshd_config.d/10-frabs-keys-only.conf
    Terminal: Turn passwords off, on Ubuntu 24.04
  4. 4

    Check and reload

    sshd -t && systemctl reload ssh && echo reloaded
    Terminal: Check and reload, on Ubuntu 24.04
  5. 5

    Confirm it worked

    Both should now say no. Open a new window and log in with your key before closing the old one.

    sshd -T | grep -iE '^(passwordauthentication|kbdinteractiveauthentication)'
    Terminal: Confirm it worked, on Ubuntu 24.04

Check It’s Fixed

Run the security report again. This check should now pass.

More Logins Guides

Stop Root Logging In Over SSH With a PasswordLimit SSH Password TriesRemove Extra Accounts With Root PowersLock Accounts With No Password