【问题标题】:Why password authentication is not allowed?为什么不允许密码验证?
【发布时间】:2013-03-15 22:19:10
【问题描述】:

我的 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

【问题讨论】:

    标签: authentication ssh passwords


    【解决方案1】:

    SSH 客户端甚至无需更改密码验证,因为所有验证尝试都用于您的公钥。

    删除未使用的公钥,添加类似

    主机 * PubkeyAuthentication=否

    ~/.ssh/config 或通过在服务器端向~/.ssh/authorized_keys 添加公钥来实际使用公钥身份验证。

    【讨论】:

    • 谢谢。是的,我的 ~/.ssh 目录中有一些公钥,但据我了解,除了 id_rsa.pub 之外,ssh 不应该使用它们来尝试进行身份验证。不过不管怎样,我觉得你的建议是对的,我会试试的。
    • 通过添加“Host * PubkeyAuthentication=no”,我可以登录需要密码验证的服务器,但无法登录需要pubkey的服务器。 :(
    • 好吧,我想通了。需要为每个需要 pubkey 身份验证的站点添加“PubkeyAuthentication yes”。
    • 顺便说一句,您也可以在 ~/.ssh/config 中使用 Host 指令执行此操作(无法得出您是否这样做或是否将其作为选项添加到命令每次都排队)。
    【解决方案2】:

    恐怕您的~/.ssh 中有太多可用的密钥。

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

    移动或移除一些未使用的键,使您的“ssh-add -l”中的键少于 5 个。

    【讨论】:

      【解决方案3】:

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

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

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

      如果您尝试使用主机名作为 hostalias 进行 ssh,远程 SSH 服务器会拒绝公钥身份验证,因为它的主机名是 host.correct.domain 。这发生在 OpenSSH v4.3 服务器版本上。

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 2012-08-06
        • 2015-01-29
        • 1970-01-01
        • 2016-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-27
        • 1970-01-01
        相关资源
        最近更新 更多