大网数据广告活动
服务器运维问答

Google Authenticator PAM on SSH blocks root login without 2FA

· 52CE 我爱测

Situation: I have activated Google Authenticator 2FA for SSH logins on Ubuntu 16.04 but made it optional in the /etc/pam.d/sshd: auth required pam_google_authenticator.so nullok I have setup the 2FA for accounts which can login f…

问题原文

原帖链接 · Arno · CC BY-SA 3.0

Situation:

I have activated Google Authenticator 2FA for SSH logins on Ubuntu 16.04 but made it optional in the /etc/pam.d/sshd:

auth required pam_google_authenticator.so nullok

I have setup the 2FA for accounts which can login from the Internet but not for accounts which are restricted to access from the same subnet because there are cronjobs running which have to transfer stuff from server to server.

This works fantastic for every account except root which is of course restricted to exactly one IP address because production and standby servers have to exchange SSL keys.

Case A: When I try to login with a normal user account with SSH key but without 2FA: no problem.

Case B: When I try to login with root with SSH key but without 2FA I get this error in /var/log/auth.log:

Aug 20 23:39:59 host01 sshd[28638]: fatal: Internal error: PAM auth succeeded when it should have failed

Your help would be very appreciated.

已采纳解答

原帖链接 · nullUser · CC BY-SA 3.0

This is the expected behavior. Assuming you had PermitRootLogin without-password, the man page for the PermitRootLogin says:

If this option is set to prohibit-password or without-password, password and keyboard-interactive authentication are disabled for root.

PAM is considered keyboard-interactive. Therefore, with PermitRootLogin without-password PAM should not allow root to login, which is the behavior you observed.

There is a difference between without-password and yes for that option. You just observed it. With yes, you can login with passwords or PAM, and with without-password you cannot login with these methods. You could still login with, e.g., a public key.

Changing PermitRootLogin to yes solves your problem, but please consider that all this headache is there for a reason. Unless you really know what you are doing, PermitRootLogin should be set to no. If you need to do rooty things remotely, login as a user withsudo privileges.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。