Note
This guide provides a copy-paste-observe list of quick instructional steps to enable MFA for better secured SSH access to your network devices.
sudo apt update && sudo apt install libpam-google-authenticator -ygoogle-authenticatorAnswer the interactive setup prompts with these recommended answers:
- Make tokens time-based:
y - Update the .google_authenticator file:
y - Disallow multiple uses of the same token:
y - Increase the original generation time limit:
n - Enable rate-limiting:
y
Save the emergency scratch codes printed on your screen.
Scan the displayed QR code using an app like Google Authenticator or Authy.
sudo nano /etc/pam.d/sshdAdd the following line:
auth required pam_google_authenticator.so nulloksudo nano /etc/ssh/sshd_configKbdInteractiveAuthentication yes
UsePAM yes
AuthenticationMethods publickey,keyboard-interactiveThe following command should not return any outputs.
sudo sshd -tsudo systemctl restart sshTip
If you had previously configured your SSH access via ssh-copy-id to enable passwordless SSH login, you can continue using it that by following the instructions below:
sudo nano /etc/pam.d/sshdComment the following line:
@include common-authsudo sshd -tsudo systemctl restart ssh
How to disable MFA for SSH ๐ ๐
Changed your mind? Not to worry. Follow the instructions below to remove MFA feature:
Comment out the following line:
# AuthenticationMethods publickey,keyboard-interactiveModify the following line:
Comment out the following line:
# auth required pam_google_authenticator.so nullokrm ~/.google_authenticator