我正在尝试设置Google-Authenticator(谷歌2因素authentication)。
相关的文件是:
[root@srv01 ~]# cat /etc/pam.d/sshd #%PAM-1.0 auth required pam_google_authenticator.so auth required pam_sepermit.so auth include password-auth account required pam_nologin.so account include password-auth password include password-auth # pam_selinux.so close should be the first session rule session required pam_selinux.so close session required pam_loginuid.so # pam_selinux.so open should only be followed by sessions to be executed in the user context session required pam_selinux.so open env_params session required pam_namespace.so session optional pam_keyinit.so force revoke session include password-auth [root@srv01 ~]# egrep -v '^#' /etc/ssh/sshd_config | sed '/^$/d' Protocol 2 SyslogFacility AUTHPRIV PermitRootLogin no PasswordAuthentication no ChallengeResponseAuthentication yes GSSAPIAuthentication yes GSSAPICleanupCredentials yes AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE AcceptEnv XMODIFIERS X11Forwarding yes Subsystem sftp /usr/libexec/openssh/sftp-server UsePAM yes Match Address 10.13.0.* PermitRootLogin yes PasswordAuthentication yes
遵循互联网上的指南,为了启用Google-2fa,您需要编辑/etc/pam.d/sshd并添加以下行:
auth required pam_google_authenticator.so
然后,您需要编辑/etc/ssh/sshd_config并更改这些行,如下所示:
PasswordAuthentication no ChallengeResponseAuthentication yes
在我的情况下,谷歌2FA工作,并允许已configuration谷歌身份validation的用户login提供的OTP和密码,但是当我尝试从同一networking的机器连接到机器上的根用户,我的密码被拒绝(甚至虽然这是正确的密码)。 当我尝试连接到root @ machine时,问题如下所示:
Using username "root". Using keyboard-interactive authentication. Password: Access denied Using keyboard-interactive authentication. Password:
并在/var/log/secure :
sshd(pam_google_authenticator)[10990]: Failed to read "/root/.google_authenticator"
我从来没有在root用户上运行过google_authenticator,所以我不知道它为什么在寻找它。
我试图达到如下:
我希望“PermitRootLogin”全局设置为“no”(当从外部连接到服务器时),但是如果远程机器IP匹配指定本地networking的规则,则设置为“yes”在configuration文件中可以看到)。
我希望configurationgoogle-2fa的用户仍然可以通过提供OTP和密码来login。
可能是/etc/pam.d/sshd中的一行放错了位置,但我不知道该放在哪里。
任何人都知道如何使这些规则工作?
您错过了手册中的一个小细节:
nullok
如果用户尚未设置OTP,则允许用户不使用OTPlogin。
你的pam.d/sshd文件应该包含这个:
auth required pam_google_authenticator.so nullok
如果你不使用nullok ,所有没有google auth设置的用户将被locking。 使用nullok ,它们仍然可以在没有2FA的情况下login,直到它们被configuration。