SSH hardening
CAUTION
create the admin user with a key and sudo before PermitRootLogin no - keep the current session open, check from a new terminal
WARNING
without KbdInteractiveAuthentication no, PAM still asks for a password
/etc/ssh/sshd_config.d/10-hardening.conf - first value wins, so 10- beats the cloud image's 50-cloud-init.conf:
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
PermitRootLogin nofish
sudo sshd -T | grep -Ei 'passwordauthentication|kbdinteractive|permitrootlogin'
sudo sshd -t && sudo systemctl restart ssh.socket ssh.servicesshd -Tshows the effective config -sshd_configis mostly commented defaultssshd -tvalidates first, Ubuntu 24.04 also runsssh.socket- from the laptop, both expect
Permission denied (publickey):
fish
ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no <user>@<host>
ssh root@<host>