2-Factor Authentication for SSH access in Linux

Опубликовано: 01 Январь 1970
на канале: InfoAlias
2,974
44

To enable two-factor authentication (2FA) using Google Authenticator for SSH in Linux, you'll need to follow these general steps:

Install Google Authenticator: If you haven't installed Google Authenticator on your Linux system, you can typically do so by using your package manager. For example, on Ubuntu or Debian-based systems, you can run the following command:

sudo apt install libpam-google-authenticator

Generate the Google Authenticator secret key: Switch to the user account that will use Google Authenticator for SSH authentication. In a terminal, run the following command:
google-authenticator

Follow the prompts to configure Google Authenticator for your user account. You'll be asked a series of questions to set up the 2FA settings. It will include generating a QR code and secret key for your account.

Scan the QR code: If you have a QR code scanner on your mobile device, use it to scan the QR code generated by google-authenticator. If you don't have a scanner, you can manually enter the secret key into the Google Authenticator app.

Back up your secret key: Make sure to store a backup of your secret key in a secure location. This will allow you to recover your Google Authenticator setup if you lose your device or need to set it up on another device.


Configure SSH: Open the SSH configuration file for editing. The file location can vary depending on your Linux distribution, but it is commonly found at /etc/ssh/sshd_config. Use your preferred text editor to open the file with root privileges:

sudo nano /etc/pam.d/sshd

Add the below line at the end of above file.

auth required pam_google_authenticator.so


Restart the SSH service: After configuring Google Authenticator, restart the SSH service to apply the changes:

sudo service ssh restart




Next edit the SSH configuration file:

sudo nano /etc/ssh/sshd_config
Change No to Yes for the following line

KbdInteractiveAuthentication yes
Restart SSH server:

Restart the service of ssh by the following command:

sudo systemctl restart sshd.service

That's it! You have now enabled 2FA using Google Authenticator for SSH in Linux. From now on, when you connect to SSH, you will be prompted to enter the verification code provided by the Google Authenticator app in addition to your regular password.

#linux
#linuxgaming
#linux_tutorial
#linuxnetwork


Смотрите видео 2-Factor Authentication for SSH access in Linux онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь InfoAlias 01 Январь 1970, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 2,974 раз и оно понравилось 44 людям.