禁用组的PAM模块

我最近在SSH服务器上使用google-authenticator启用了双因素身份validation。 但是我现在面临一个问题:

我在服务器上有一组不同的用户,我用于SFTP,但该组不再能够登录,因为没有为组中的用户设置2FA。 是否可以为该组禁用google-authenticator模块? 为组中的用户启用它不是一种选择,因为多个用户将使用此帐户。

PS:我使用openssh-server

您可以在pam_google_authenticator之前使用pam_succeed_if模块(请参阅手册页)跳过您的pam_google_authenticator此部分:

 # the other authentication methods, such as @include common-auth auth [success=1 default=ignore] pam_succeed_if.so user ingroup group auth required pam_google_authenticator ... 

一些SFTP客户端可以处理2FA。 例如,我正在使用2FA与FileZilla和WinSCP,他们的工作。 此外,我已设置ssh-key身份validation,它与2FA一起使用。

不过你的问题很有意思,我做了一个简短的调查。 我找到了这个答案 。

因此,可以(并且很容易)运行单独的ssh实例。 我已经测试过了。

  1. 制作sshd_config文件的单独副本。

     $ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_pwd $ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_2fa 
  2. 编辑这些新的config文件。 你必须改变的一件事是shh端口。 根据例子:

    2.a) sshd_config_pwd具体行是:

     Port 1022 ... PasswordAuthentication yes ChallengeResponseAuthentication no UsePAM no 

    2.b) sshd_config_2fa具体行是:

     Port 2022 ... PasswordAuthentication no ChallengeResponseAuthentication yes UsePAM yes 
  3. 打开防火墙所需的端口。 根据例子:

     $ sudo ufw limit 1022 $ sudo ufw limit 2022 
  4. 运行新的ssh实例:

     $ sudo /usr/sbin/sshd -f /etc/ssh/sshd_config_pwd $ sudo /usr/sbin/sshd -f /etc/ssh/sshd_config_2fa 

而已。