Note: this instruction is based on the Ubuntu server. If you are using another distribution, some of the commands may vary.
Installing Two-Factor Authentication for SSH
Open a terminal session on the machine where you will install the two-factor authentication, Type the following: To complete the installation, run: Tip: learn how to use SSH X-forwarding to run remote apps.
Configuring SSH Two-Factor Authentication
You will be prompted with a series of questions. In most situations, you can type “y” (yes) as the answer. Anytime the settings are wrong, press Ctrl + C, then type google-authenticator again to reset the settings. After this question, you should see your secret key and emergency code. Record and save the details. You will need the secret key to set up the Google Authenticator app later.
Configure SSH to Use the Google Authenticator
Setting Up a Key in Google Authenticator
When you connect via SSH to your remote computer, you will see the request for the verification key. Note: two-factor authentication only works for password-based logins. If you are already using a public/private key for your SSH session, it will bypass the two-factor authentication and log you in directly. Also, check out more ways to secure your SSH server. Image credit: Unsplash. All alterations and screenshots by Ramces Red.