The dual lock is set. SSH keys replaced passwords. TOTP added the second factor. fail2ban is watching. PAM enforces complexity and lockout. A compromised password alone is useless. A stolen key alone is useless. The attacker needs both, with the phone in hand, while the brute-force timer is ticking.
1
PAM is the authentication framework beneath every login. All hardening -- TOTP, lockout, complexity -- is implemented as PAM modules.
2
PAM configuration lives in /etc/pam.d/. Editing common-auth affects every service that includes it. Test before closing your session.
3
SSH keys should be ed25519. Always use a passphrase. Correct permissions: ~/.ssh/ 700, authorized_keys 600.
4
TOTP uses a shared secret and the current time window to generate codes. Codes expire every 30 seconds. Phishing a valid code gives an attacker under 30 seconds before it is worthless.
5
AuthenticationMethods publickey,keyboard-interactive in sshd_config enforces both SSH key AND TOTP. Neither alone is sufficient.
6
fail2ban monitors log files for failure patterns and adds iptables DROP rules. Always whitelist your management IP in ignoreip.
7
pam_faillock replaces pam_tally2 on Ubuntu 22.04. Lock after 5 failures, unlock after 15 minutes is a reasonable default.
8
Set PermitRootLogin no and PasswordAuthentication no in sshd_config. Verify syntax with sshd -t before reloading.
9
Save TOTP scratch codes offline. Test every PAM change from a second open session. These two rules prevent most authentication lockouts.