当UsePAM设置为“ no”时,SSH公钥身份验证失败


19

要禁用密码身份验证,请在我的计算机中设置以下值 sshd_config

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

当我尝试使用私钥登录时,我得到

Permission denied (publickey).

如果更改UsePAMyes,则可以使用我的私钥登录。为什么?

我正在从OSX连接到Ubuntu 12.04 64位主机

ssh -i ~/.ssh/deploy -l deploy localhost -p 2222 -v

这是详细的ssh输出:

OpenSSH_5.9p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/<user>/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 2222.
debug1: Connection established.
debug1: identity file /Users/<user>/.ssh/deploy type 1
debug1: identity file /Users/<user>/.ssh/deploy-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 50:db:75:ba:11:2f:43:c9:ab:14:40:6d:7f:a1:ee:e3
debug1: Host '[localhost]:2222' is known and matches the RSA host key.
debug1: Found key in /Users/<user>/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/<user>/.ssh/key1
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: /Users/<user>/.ssh/deploy
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

您是否在调试模式下运行sshd并检查它生成的日志?
迈克尔·汉普顿

我们肯定会需要更多日志。我在VM中复制了您的情况(使用Fedora 17),它对我有用。
Scott Pack

Answers:


15

如果没有PAM(可插入身份验证模块),则需要更复杂的ssh配置来进行身份验证。您实际上在寻找这个:

# grep Password /etc/ssh/sshd_config 
PermitEmptyPasswords no
PasswordAuthentication no

这将禁用密码登录。确保正确建立了公共密钥设置。


4
这不是真的。实际上,许多指南都建议仅将设置ChallengeResponseAuthenticationPasswordAuthentication和设置UsePAMno仅使用公钥身份验证。我从来没有在这样的环境中工作过,所以我不能轻易给出它还不能工作的真实原因。
Scott Pack

3
这就是为什么我首先将它设置为no的原因,因为我发现的每个指南都做到了!
Erik Aigner

我会纠正的。你是对的,斯科特。也就是说,如果他不想使用pam_unix,则需要配置pam_nologin(或允许root用户访问。) www-uxsup.csx.cam.ac.uk/pub/doc/suse/sles9/adminguide-sles9 /…
Stephan

9

您的用户帐户是否被锁定?您可以解锁用户帐户

passwd -u username

或锁定用户帐户但启用PAM:

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM yes

1
另外,passwd -u如果用户密码为空,则失败。使用echo username:$(head -c12 /dev/urandom |base64) |chpasswd设置随机有效的密码。
2016年

usermod -p '*' username将让您将所有三个设置为“ no”,并且仍然允许“用户名”使用公用密钥身份验证进行连接,而无需设置一次性密码。
大卫,
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.