【问题标题】:Having trouble with ssh and authorized_keysssh 和 authorized_keys 有问题
【发布时间】:2012-04-20 13:33:42
【问题描述】:

我正在从 server1 SSH 到 server2。我生成了 id_rsaid_rsa.pub 文件。如果我 ssh 到 mike@server2 它工作正常,但 ssh 到 john@server2 没有密码就无法工作。 mike 和 john 主目录都包含“.ssh”,即 chmod 700,该文件夹包含“authorized_keys”,其中仅包含先前生成的 id_rsa.pub 文件的内容(并且是 chmod 600)。两者的内容是一样的。

服务器 1:Linux x86_64 x86_64 x86_64 GNU/Linux

服务器 2:AIX 5.3.0.0 64 位

命令 1,用户 Mike(无需密码即可使用): ssh -v -n -o StrictHostKeychecking=no -o NumberOfPasswordPrompts=0 mike@server2 echo Hello

~drwx------ 7 mike mike 4096 Jan 19 2011 .

~/.ssh drwx------ 2 mike mike 256 Nov 28 16:39 .ssh

~/.ssh/authorized_keys -rw------- 1 mike mike 823 Apr 06 11:56 .ssh/authorized_keys


命令 2,用户 John(需要密码) ssh -v -n -o StrictHostKeychecking=no -o NumberOfPasswordPrompts=0 john@server2 echo Hello

~drwx------ 12 john jgroup 4096 Apr 06 23:13 .

~/.ssh drwx------ 2 john jgroup 256 Apr 06 23:56 .ssh

~/.ssh/authorized_keys -rw------- 1 john jgroup 414 Apr 06 11:55 .ssh/authorized_keys

ssh -v 以上命令 2 的输出:

OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to server2 [X.X.X.X] port 22.
debug1: Connection established.
debug1: identity file /home/will/.ssh/identity type -1
debug1: identity file /home/will/.ssh/id_rsa type 1
debug1: identity file /home/will/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.0
debug1: match: OpenSSH_5.0 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc 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: Host 'server2' is known and matches the RSA host key.
debug1: Found key in /home/will/.ssh/known_hosts:838
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received

This network/computer system is for the use of authori...
.........................................................

debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /home/will/.ssh/identity
debug1: Offering public key: /home/will/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /home/will/.ssh/id_dsa
debug1: Next authentication method: keyboard-interactive
debug1: Next authentication method: password
debug1: No more authentication methods to try.
Permission denied (publickey,password,keyboard-interactive).

任何人都知道为什么它可以与一个用户而不是另一个用户一起工作(两者都在同一台服务器上)?

【问题讨论】:

    标签: ssh authorized-keys


    【解决方案1】:

    密钥认证失败的常见原因:

    • ~/.ssh 上的权限或所有权设置不正确(我看到你已经检查了这些)
    • 公钥已损坏
    • 公钥与私钥的密钥不同

    还要检查服务器的auth.log

    【讨论】:

    • 如果公钥/私钥有问题,会不会也影响连接其他ID?
    • 请注意“公钥用于与私钥不同的密钥”。从文件的大小我猜你在第一个帐户的授权密钥中有另一个密钥。也许其他密钥实际上是您 ssh 时正在使用的密钥?
    • 我从麦克的 authorized_keys 中删除了另一个密钥,它仍然可以与该用户一起使用。
    • 检查auth.log 为我解决了这个问题。问题是“AllowGroups 中没有列出任何用户组”。将组添加到 /etc/ssh/sshd_config 并重新启动 sshd 就可以了。
    【解决方案2】:

    您能够以 Mike 的身份登录真是个笨蛋。您可以尝试制作一个authorized_keys2 文件。 authorized_keys 不适用于所有版本的 OpenSSH。

    ln -s authorized_keys authorized_keys2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-01
      • 1970-01-01
      • 2019-03-22
      • 2013-03-22
      • 2017-03-21
      • 2023-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多