Tools
Log in
English

Learn to codeSecurity check

SSH password login allowed

MediumL02Linux servers

Switch SSH to key-only logins and put an end to password guessing.

What is the risk

SSH open to the internet gets thousands of password guesses a day. One account with a weak password is enough.

Key login needs the private key file, so guessing does not work.

How to check

Linux

sudo sshd -T | grep -iE '^(passwordauthentication|kbdinteractiveauthentication)'

Fix it if either says yes.

How to fix

Your computer

ssh-keygen -t ed25519
ssh-copy-id user@your-server

Create a key on your own computer and copy it to the server. Windows 10 and 11 PowerShell also have ssh-keygen. Without ssh-copy-id, paste the public key (.pub) into ~/.ssh/authorized_keys on the server.

Linux

printf 'PasswordAuthentication no\nKbdInteractiveAuthentication no\n' | sudo tee /etc/ssh/sshd_config.d/10-appdogu-pw.conf
sudo sshd -t

Do this only after a key login works in a new window. The 10- prefix makes it load before 50-cloud-init.conf on cloud images. If sshd -t says the option is unknown, your OpenSSH is older, so use ChallengeResponseAuthentication no instead of the second setting.

Debian / Ubuntu

sudo systemctl reload ssh

RHEL / Rocky / Alma

sudo systemctl reload sshd

How to prevent it

  • Protect private keys with a passphrase.
  • Remove keys you no longer use from authorized_keys.
  • Narrow the SSH port with the firewall (L03).

Check again after fixing

Linux

sudo sshd -T | grep -iE '^(passwordauthentication|kbdinteractiveauthentication)'

Both should say no.

Run the downloaded check again and make sure this item passes.

Security check home