为什么不允许密码认证?

6

我的ssh现在似乎只接受公钥身份验证。即使我确定在我的/etc/ssh/ssh_config中 "PasswordAuthentication" 是打开的。这是我的ssh日志。我想知道为什么我的ssh不允许密码身份验证?P.S: 我可以通过在命令行中添加 "-o PubkeyAuthentication=no" 来强制ssh使用密码身份验证。

markz@markz-hp6200:~$ ssh -l lab 10.19.170.114 -v
OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /home/markz/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 10.19.170.114 [10.19.170.114] port 22.
debug1: Connection established.
debug1: identity file /home/markz/.ssh/id_rsa type -1
debug1: identity file /home/markz/.ssh/id_rsa-cert type -1
debug1: identity file /home/markz/.ssh/id_dsa type -1
debug1: identity file /home/markz/.ssh/id_dsa-cert type -1
debug1: identity file /home/markz/.ssh/id_ecdsa type -1
debug1: identity file /home/markz/.ssh/id_ecdsa-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.9p1 Debian-5ubuntu1
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: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA d5:c0:00:1b:bf:54:56:a0:c6:68:6f:62:a4:1a:e3:e1
debug1: Host '10.19.170.114' is known and matches the ECDSA host key.
debug1: Found key in /home/markz/.ssh/known_hosts:10
debug1: ssh_ecdsa_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,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: markz@markz-hp6200
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: markz@markz-hp6200
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: markz@markz-hp6200
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: markz@markz-hp6200
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: markz@markz-desktop
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: markz@markz-desktop
Received disconnect from 10.19.170.114: 2: Too many authentication failures for lab
3个回答

5

SSH客户端无法尝试密码认证,因为所有的认证尝试都用于公钥。

删除未使用的公钥,添加以下内容:

Host * PubkeyAuthentication=no

~/.ssh/config或者在服务器端将公钥添加到~/.ssh/authorized_keys来实际使用公钥认证。


谢谢。是的,我在我的~/.ssh目录中有一些公钥,但根据我的理解,ssh不应该使用它们来尝试认证,除了id_rsa.pub。但无论如何,我认为你的建议是正确的,我会尝试一下。 - Mark Zhang
通过添加“Host * PubkeyAuthentication=no”,我可以登录需要密码验证的服务器,但无法登录需要公钥验证的服务器。 :( - Mark Zhang
好的,我弄明白了。需要为每个需要公钥身份验证的站点添加“PubkeyAuthentication yes”。 - Mark Zhang
顺便提一下,您也可以在 ~/.ssh/config 中使用“Host”指令来完成这个操作(无法确定您是否已经这样做了,或者您是否只是每次在命令行中添加选项)。 - Ronald Paul

5

很抱歉,您的~/.ssh中有太多可用的密钥。

ssh似乎会首先尝试使用所有可用的密钥,但目标机器只接受5个身份验证请求,因此没有机会尝试密码身份验证。

移动或删除一些未使用的密钥,以便在"ssh-add -l"中拥有少于5个密钥。


1
我还发现,当您没有设置与服务器报告自身相同的主机名时,此错误会弹出,即使您的帐户有效并且ssh公钥权限已正确设置。

例如,您在本地/ etc / hosts中覆盖了主机名,提供了一个别名,该别名与远程SSH服务器的实际主机名不同。

XX.XX.YY.YY   host.correct.domain   hostalias

如果您尝试使用主机别名hostalias进行ssh连接,则远程SSH服务器会拒绝公钥身份验证,因为其主机名为host.correct.domain。这种情况发生在OpenSSH v4.3服务器版本上。
希望这可以帮助您。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接