Do you have 2FA for your SSH access on your server? If not, here is how you can setup 2FA with an authenticator app.
👇
First, you need to install the Google Authenticator package:
sudo apt-get install libpam-google-authenticator
Then run the app to configure it:
$ google-authenticator
Do you want authentication tokens to be time-based (y/n)
Answer `yes`, and read the QR code in your app of choice, then enter the generated code and make sure you save your recovery codes.
Answer `yes` to the "Do you want me to update your "/root/.google_authenticator" file? (y/n)" question.
Set the rest of the config options based on your preference and threat level (rate-limiting is highly recommended).
Next, we'll need to enable the 2FA for `sshd` by editing `/etc/pam.d/sshd`. Find the line "
@include common-auth", and comment it out, then append this to the end of the file:
auth required pam_permit.so
auth required pam_google_authenticator.so nullok
Now open "/etc/ssh/sshd_config" and:
- find "KbdInteractiveAuthentication" and set it to "yes"
- find "ChallengeResponseAuthentication" and set it to "yes"
- find "AuthenticationMethods" and set to "publickey,keyboard-interactive"
If you can't find these settings, just append them as new lines to the end of the file.
Restart "sshd" by running "sudo service sshd restart". You'll then have 2FA enabled for SSH on your server.