# Debian/Ubuntu sudo apt update sudo apt install libpam-google-authenticator -y # RHEL sudo dnf install epel-release -y sudo dnf install google-authenticator -y
google-authenticatorScan the QR code using a TOTP app (Google Authenticator, Authy, etc.) and answer
yes to all prompts. This generates a .google_authenticator file in your home directory.
QR code not showing? Install qrencode (sudo apt install libqrencode3 or sudo dnf install qrencode).
sudo nano /etc/pam.d/sshdAdd this line at the top:
auth required pam_google_authenticator.sonano not found? Install it with
sudo apt install nano or sudo yum install nano.
#Ubuntu/Debian/RHEL sudo nano /etc/ssh/sshd_config #RHEL 9+ (AlmaLinux 9+, Rocky 9+) sudo nano /etc/ssh/sshd_config.d/50-redhat.confEnsure the following lines are present:
ChallengeResponseAuthentication yes UsePAM yes KbdInteractiveAuthentication yes
# Debian/Ubuntu sudo systemctl restart ssh # RHEL sudo systemctl restart sshd
ssh USERNAME@IPAfter entering your password or SSH key, you'll be prompted to enter the 2FA verification code from your authenticator app. If successful, you’ll be logged in securely.
If you want to disable SSH Two-Factor Authentication (2FA) on your Linux VPS, follow these steps carefully. Keep a console or secondary SSH session open to avoid locking yourself out during the process.
Remove PAM Google Authenticator Line
Delete the line that enables Google Authenticator in the PAM SSH configuration file:sudo sed -i '/pam_google_authenticator.so/d' /etc/pam.d/sshd
Revert SSH Configuration
Reset SSH settings to disable 2FA prompts:#Ubuntu/Debian/RHEL sudo sed -i 's/^#*ChallengeResponseAuthentication.*/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config sudo sed -i 's/^#*KbdInteractiveAuthentication.*/KbdInteractiveAuthentication no/' /etc/ssh/sshd_config #RHEL 9+ (AlmaLinux 9+, Rocky 9+) sudo sed -i 's/^#*ChallengeResponseAuthentication.*/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config.d/50-redhat.conf sudo sed -i 's/^#*KbdInteractiveAuthentication.*/KbdInteractiveAuthentication no/' /etc/ssh/sshd_config.d/50-redhat.conf
Test SSH Configuration and Restart
Before applying the changes, validate the SSH configuration:sudo sshd -tIf no errors appear, restart SSH:
sudo systemctl restart sshdImportant Notes
UsePAM enabled unless you are sure it’s not needed by other services.# Install required packages # Ubuntu / Debian sudo apt update sudo apt install libpam-google-authenticator libqrencode3 -y # RHEL-based (AlmaLinux, Rocky, CentOS) sudo dnf install epel-release -y sudo dnf install google-authenticator qrencode -y # Run setup for your user (scan QR code) google-authenticator # Add PAM module sudo sed -i '$a auth required pam_google_authenticator.so' /etc/pam.d/sshd # Update SSH config (Ubuntu/Debian & CentOS 7) sudo sed -i '/^#\?ChallengeResponseAuthentication.* /d' /etc/ssh/sshd_config sudo sed -i '$a ChallengeResponseAuthentication yes' /etc/ssh/sshd_config sudo sed -i 's/^#*UsePAM.*/UsePAM yes/' /etc/ssh/sshd_config sudo sed -i 's/^#*KbdInteractiveAuthentication.*/KbdInteractiveAuthentication yes/' /etc/ssh/sshd_config # AlmaLinux / Rocky / RHEL 9+ SSH config sudo sed -i 's/^#*ChallengeResponseAuthentication.*/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config.d/50-redhat.conf sudo sed -i 's/^#*UsePAM.*/UsePAM yes/' /etc/ssh/sshd_config.d/50-redhat.conf sudo sed -i 's/^#*KbdInteractiveAuthentication.*/KbdInteractiveAuthentication yes/' /etc/ssh/sshd_config.d/50-redhat.conf sudo grep -q '^KbdInteractiveAuthentication' /etc/ssh/sshd_config.d/50-redhat.conf || sudo sed -i '$a KbdInteractiveAuthentication yes' /etc/ssh/sshd_config.d/50-redhat.conf # Restart SSH # Ubuntu / Debian sudo systemctl restart ssh # RHEL-based sudo systemctl restart sshd
By enabling SSH 2FA on Linux, you add a powerful security layer to your Evoxt VPS. Whether you're managing websites, Nextcloud, or critical infrastructure, this step greatly reduces the risk of unauthorized access.
For added security, you can also set up SSH keys in conjunction with 2FA.
Need help? Open a support ticket and Evoxt's support team will assist you.