我如何使用OpenSSH启用密码和公钥authentication

我想为sshdvalidation用户的公钥,然后提示input密码,而不是一个或另一个。 这可能吗?

目前没有。 但有一些补丁漂浮在应该添加这个。

请参阅https://bugzilla.mindrot.org/show_bug.cgi?id=983

从OpenSSH 6.2 (2013年3月发布)开始,最终可以使用AuthenticationMethodsconfiguration选项。

例如,您可以sshd_config下行添加到sshd_config以同时需要公钥和密码身份validation:

 AuthenticationMethods publickey,password 

login时, sshscp将首先执行公钥authentication,然后提示input密码:

 $ ssh [email protected] Authenticated with partial success. [email protected]'s password: 

如果您的私钥文件上有密码,那么当然首先会提示您input密码。 使用PuTTY的示例:

 Using username "user". Authenticating with public key "rsa-key-20131221-user" Passphrase for key "rsa-key-20131221-user": Further authentication required [email protected]'s password: 

这是可能的,但以一种克鲁吉什和有限的方式。 首先你只允许公钥authentication。 然后在/etc/ssh/sshd_config添加一个执行脚本的ForceCommand来检查密码。

这个脚本将会破坏SFTP,除非你检查这个命令是否是sftp,并允许它没有密码。

我从来没有尝试过,所以有人可能会看到更多的问题。

OpenSSH在RHEL / CentOS 6.3中现在支持这个function,虽然我在OpenSSH发行说明中找不到它。 从RHEL发行说明 :

SSH现在可以设置为需要多种身份validation方式(而以前的SSH允许多种身份validation方式,其中只有一种是成功login所需的)。 例如,login到启用了SSH的计算机上需要input密码和公钥。 可以在/etc/ssh/sshd_config文件中configurationRequiredAuthentications1RequiredAuthentications2选项,以指定成功login所需的身份validation。例如:

  ~]# echo "RequiredAuthentications2 publickey,password" >> /etc/ssh/sshd_config 

有关上述/etc/ssh/sshd_config选项的更多信息,请参阅sshd_config手册页。