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

Combination of SSH key auth, and two-factor authentication

· 52CE 我爱测

I was wondering if it is possible to accomplish the following, all at the same time: Disable root logins Enable SSH login for personal user, only via SSH keys Enable SSH login for unprivileged user, with password authentication a…

问题原文

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

I was wondering if it is possible to accomplish the following, all at the same time:

  • Disable root logins
  • Enable SSH login for personal user, only via SSH keys
  • Enable SSH login for unprivileged user, with password authentication and two-factor authentication only

Using the Match block in sshd_config I was able to set this up so that in general PasswordAuthentication was disabled except for the unprivileged user (lets call it peon). SSH keys were required for logging in to the personal user (who has sudo capabilities).

However, when I try to enable two-factor authentication (pam_google_authenticator) I have to turn on ChallengeResponseAuthentication which seems to not work in a Match block, and is therefore turning password authentication back on for everyone.

Is there a way to accomplish this? I'm not overly great with this type of stuff, so detailed explanations would be really appreciated.

Thanks!

社区高分解答

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

Recent versions of openssh include the AuthenticationMethods option:

Debian backported openssh-6.2 a while back, so I expect this to be available in Raspbian as well.

Specifies the authentication methods that must be successfully completed for a user to be granted access.

You can have the main block of your sshd_config with ChallengeResponseAuthentication enabled:

ChallengeResponseAuthentication yes
PasswordAuthentication no
PermitRootLogin no

and then use AuthenticationMethods in your Match blocks (use Group matching instead of User matching to ease scalabity):

Match Group personal
  AuthenticationMethods publickey

Match Group peon
  PasswordAuthentication yes
  AuthenticationMethods publickey,keyboard-interactive

Aditionally, you can use pam_succeed_if(8) to trigger the two-factor-authentication only if a matching group requires it:

 auth required pam_succeed_if.so quiet user ingroup peon

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

资料来源与适用范围

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

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

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