Two-factor Authentication
In this guide, we will explain how to set up two-factor authentication on an Ubuntu Linux instance, enhancing your server’s security with an additional verification layer.
Last updated
In this guide, we will explain how to set up two-factor authentication on an Ubuntu Linux instance, enhancing your server’s security with an additional verification layer.
Last updated
Two-factor authentication (2FA) adds an extra layer of security to your Ubuntu system by requiring two forms of identification before granting access. In addition to the usual username and password, 2FA requires an additional piece of information, such as a one-time password (OTP) generated by an authenticator app.
First of all, download the Google Authenticator app on your mobile device
Here are some methods to enable 2FA on Ubuntu:
Run the google-authenticator command as the user you want to log in (not as root):
Follow the prompts to set up 2FA. You’ll need an authenticator app (e.g., Google Authenticator or Authy) on your mobile device to scan the QR code.
Edit the /etc/pam.d/sshd file and add the following line at the end.
auth required pam_google_authenticator.so
save the file and exit
Edit the /etc/ssh/sshd_config file
KbdInteractiveAuthentication no > Yes
Edited both the file restart service
Open the Command prompt to access the server
ssh user@IP_Addresss
Enter the password and the verification code from your Google Authenticator app on your mobile device.