1. Check the current setting
This asks sshd what it is actually using, with defaults and included files resolved.no, you are done. If it says yes, continue.
A fresh Ubuntu install says
yes. Ubuntu ships the setting commented out, and
sshd enables password login when the setting is absent.2. Add your key and confirm it works
From your own computer:3. Turn off password login
On the host:PasswordAuthentication line and set it to:
4. Check for files that override it
Ubuntu reads extra config files from/etc/ssh/sshd_config.d/, and they win over
the main file. This is the most common reason the change looks done but the
machine still fails.
yes to no, or delete the line.
/etc/ssh/sshd_config begins with Include /etc/ssh/sshd_config.d/*.conf, and
OpenSSH keeps the first value it finds for a setting, so anything in that folder
is read first. See the
Ubuntu Server OpenSSH guide.5. Test the config, then restart
sshd -t checks the file without touching the running service. Editing the file
alone changes nothing until you restart.
Ubuntu 24.04 starts sshd on demand when a connection arrives, rather than running
it constantly as 22.04 does. The command above is correct on both.
6. Verify
Confirm the running service is now refusing passwords.yes, go back to step 4. Then log in once more from your own
computer to confirm, and close your original session.
Machines are rechecked about once an hour. If yours was already flagged, the
error can take a couple of checks to clear after you fix it.
If you are locked out
You need access that does not go through SSH. Use the machine’s IPMI, iDRAC, iLO, or other BMC console, or plug a monitor and keyboard into it. Then setPasswordAuthentication yes and run: