1.8 KiB
1.8 KiB
SSH
Add TOTP on ssh connection
For a more secure ssh connection, you can add TOTP (Time-based One-Time Password) to your ssh connection. This will require you to enter a password and a TOTP code to connect to your server. This is a good way to add an extra layer of security to your server.
Installing Google Authenticator PAM
sudo apt install libpam-google-authenticator
Configuring SSHD for Google PAM
- Edit the sshd configuration file
sudo nano /etc/pam.d/sshd - Modified the file to look like this
Comment out the
# PAM configuration for the Secure Shell service # Standard Un*x authentication. #@include common-auth . . . # Standard Un*x password updating. @include common-password auth required pam_google_authenticator.so nullok@include common-authfor disable password authentication.nullokallows users without a TOTP code to connect without one. - Edit the sshd configuration file
sudo nano /etc/ssh/sshd_config - Add the following line to the bottom of the file
. . . # Change to yes to enable challenge-response passwords (beware issues with # some PAM modules and threads) ChallengeResponseAuthentication yes . . . UsePAM yes AuthenticationMethods publickey,password publickey,keyboard-interactive . . . - Restart the sshd service
sudo systemctl restart sshd
Generating the Google Authenticator QR Code
- Run the following command
google-authenticator - Answer the following questions
- Scan the QR code with your Google Authenticator app
- Save the emergency scratch codes in a safe place
- Restart the sshd service
sudo systemctl restart sshd