尝试使用公钥(无密码)获取SSH +谷歌authentication工作在Ubuntu 14.04.1

我使用Ubuntu 14.04.1(OpenSSH 6.6和libpam-google-authenticator 20130529-2)。

我正在尝试设置公钥authentication的SSHlogin(无密码),并提示用户input来自Google Authenticator的代码。

遵循/适应这些说明已经得到了我的密码提示以及Google身份validation提示:

  • https://scottlinux.com/2013/06/02/use-google-authenticator-for-two-factor-ssh-authentication-in-linux/
  • http://www.howtogeek.com/121650/how-to-secure-ssh-with-google-authenticators-two-factor-authentication/
  • https://wiki.archlinux.org/index.php/Google_Authenticator和https://wiki.archlinux.org/index.php/SSH_keys#Two-factor_authentication_and_public_keys
  • https://www.digitalocean.com/community/tutorials/how-to-protect-ssh-with-two-factor-authentication

我已经安装了软件包,编辑了我的/etc/ssh/sshd_config/etc/pam.d/ssh文件

/etc/ssh/sshd_config

 ChallengeResponseAuthentication yes AuthenticationMethods publickey,keyboard-interactive UsePAM yes 

并在/etc/pam.d/ssh的底部:

 auth required pam_google_authenticator.so nullok # (I want to give everyone a chance to set up their 2FA before removing "nullok") 

我知道PAM是顺序依赖的,但也是sshd_config

我究竟做错了什么? 任何帮助,将不胜感激。

工作得很好,首先做到了:

 apt-get install libpam-google-authenticator 

/etc/pam.d/sshd我已经改变/添加了以下几行(在顶部):

 # @include common-auth auth required pam_google_authenticator.so 

并在/etc/ssh/sshd_config

 ChallengeResponseAuthentication yes UsePAM yes AuthenticationMethods publickey,keyboard-interactive PasswordAuthentication no 

运行良好,我现在收到validation后公钥validation码提示。 我不知道我将如何使用密码+令牌或密钥+令牌进行身份validation,因为我现在已经有效地从PAM中删除了密码validation方法。

使用Ubuntu 14.04.1 LTS(GNU / Linux 3.8.0-19-generic x86_64)和ssh -v:OpenSSH_6.6.1p1 Ubuntu-2ubuntu2,OpenSSL 1.0.1f 2014年1月6日

Linus Kendall的答案应该在较老的系统上工作,但在较新的Linux机器上则是有问题的; 在我基于Linux的基于web服务器,该configuration导致在收到我的ssh密钥(即我需要所有3)后,pam要求我的validation码和我的密码。

一个简单的解决scheme,可以防止这个问题,并应该在每个系统上工作,就是将/etc/pam.d/sshd的条目更改为:

 auth sufficient pam_google_authenticator.so 

然后对Linus提到的“/ etc / ssh / sshd`进行相同的编辑:

 ChallengeResponseAuthentication yes UsePAM yes AuthenticationMethods publickey,keyboard-interactive PasswordAuthentication no 

在服务器接受你的公钥之后,应该询问你的身份validation器令牌。 它不应该要求你的密码。

作为一个侧面说明,如果你想有一个SFTP的用户帐户,你可能需要绕过谷歌authentication,以使其工作。 这里是如何安全地使用sftp监狱的build议。 在etc/ssh/sshd_config

 Subsystem sftp internal-sftp Match User ftp-user PasswordAuthentication yes AuthenticationMethods password ChrootDirectory /path/to/ftp/dir ForceCommand internal-sftp 

你需要在/ path / to / ftp / dir root权限下写chown root:root /path/to/ftp/dir (比如chown root:root /path/to/ftp/dirchmod 755 /path/to/ftp/dir 。这个目录也需要安全的权限,我通常做这个的方法是把chroot目录设为/home/shared/user ,在那里创build一个目录(例如'data'),然后挂载任何我想要共享的目录: sudo mount -o bind /path/to/ftp/dir /home/shared/user/data

如果你遵循所有这些步骤,你将有公共密钥+谷歌身份validationlogin您的SSH用户,并有一个function密码保护sftp账户进行数据传输。

我终于可以通过在/etc/pam.d/sshd的顶部放置auth [success=done new_authtok_reqd=done default=die] pam_google_authenticator.so nullok来得到这个工作。

根据pam.d手册页 :

  • success=done意味着如果Google身份validation器退出,则不会执行更多身份validation,这意味着无需附encryption码提示。
  • default=die意味着如果Google Authenticator拒绝login尝试,身份validation将立即失败,跳过密码提示。

所以[success=done new_authtok_reqd=done default=die]sufficientrequisite控制值之间的混合,因为我们希望从两个行为:如果成功,立即终止(足够),如果失败,也立即终止(必要)。

请注意,pam_google_authenticator.so的nullok参数表示如果没有为用户find~/.google_authenticator文件,则公钥authentication将正常进行。 如果我只想使用2FAlocking我的帐户的一个子集,这非常有用。