If systems are already using passwords for SSH authentication, one way to increase security for the users without needing to immediately switch to Public Keys is to use 2FA. Implementing Google Authenticator for SSH authentication adds an extra layer of security to your server environment.  Google Authenticator generates time-based one-time passwords (TOTPs) that are only valid for a short period, typically 30 seconds. This means even if an attacker manages to obtain a user's password, they would still need access to the user's mobile device where the authenticator app is installed to generate the correct code for authentication. By enabling Google Authenticator, you significantly enhance the security posture of your SSH server.


The following instructions for set up are using an Ubuntu server as an example for configuration.



sudo apt-get install libpam-google-authenticator -y



google-authenticator




sudo vi /etc/ssh/sshd_config




sudo vi /etc/pam.d/sshd


auth   required   pam_google_authenticator.so



sudo systemctl restart sshd


With these steps, you should have Google Authenticator set up for SSH such that the server will prompt for the users password then 2FA token on login.