How-Tos

How-To: Turn Off SSH Password Logins and Prove It Took Effect With sshd -T

Leave a comment

Password-guessing bots hammer every SSH server on the internet, and that includes the accounts you set up for bots and AI agents. Keys only is the real fix. Rate-limiting with nftables helps, but this is the part that matters. Make sure your key login works first, and keep a second session open while you change things.

1. See what sshd is actually using

sudo sshd -T | grep -Ei '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin|pubkeyauthentication)'

sshd -T prints the effective config after every include, which is what you want. Editing one file can be overridden by another in sshd_config.d.

2. Add a drop-in

sudo tee /etc/ssh/sshd_config.d/10-keys-only.conf >/dev/null <<'EOF'
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
PubkeyAuthentication yes
EOF

OpenSSH uses the first value it finds for most settings, so a low number like 10- makes sure yours wins over other drop-ins. Check that your main sshd_config has an Include /etc/ssh/sshd_config.d/*.conf line near the top.

3. Test, then reload

sudo sshd -t && sudo systemctl reload sshd   # Debian/Ubuntu: ssh

Run step 1 again and confirm it says passwordauthentication no.

4. Prove it from another machine

ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password user@server

You should get Permission denied (publickey) without ever seeing a password prompt.

Tips

  • Give bot and agent accounts their own keys, never shared passwords.
  • If a Match block turns passwords back on for some users, sshd -T -C user=name,host=x,addr=y shows the result for that case.

God Bless, and Use the Source!

References & Further Reading

Subscribe (RSS) Follow How-Tos via RSS

Leave a note

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.