OpenSSH 2FA Google Auth
Let’s give a try with Alpine Linux, OpenSSH and 2FA with Google Authenticator.
add Packages
apk add openssh openssh-server-pam google-authenticator openssh-doc google-authenticator-doc libqrencode
Configure GoogleAuth
touch /etc/pam.d/sshd
ln /etc/pam.d/sshd /etc/pam.d/sshd.pam
cat << 'EOF' >> /etc/pam.d/sshd.pam
account include base-account
auth required pam_env.so
auth required pam_nologin.so successok
auth required /lib/security/pam_google_authenticator.so echo_verification_code grace_period=57600 nullok
auth required pam_unix.so md5 sha512
EOF
update sshd_config
cat << 'EOF' >> /etc/ssh/sshd_config
PasswordAuthentication no
AuthenticationMethods any
UsePAM yes
EOF
Restart SSHD
service sshd restart
Setup User
su - USERNAME
google-authenticator
Response