ssh-copy-id 不起作用

jac*_*hab 32 linux ssh

我正在尝试在 CentOS 5.4 上设置无密码 SSH 登录:

  1. 我在客户端生成了 RSA 公钥。
  2. 从客户端到服务器的 ssh-copy-id。
  3. 验证 ~/.ssh/authorized_keys 包含客户端密钥。

客户端仍然提示输入密码。我错过了什么?

谢谢。

编辑:按照建议检查 ssh_config 和权限。这是来自客户端的调试信息:

debug2: key: /home/saguna/.ssh/identity ((nil))
debug2: key: /home/saguna/.ssh/id_rsa (0x2b31921be9a0)
debug2: key: /home/saguna/.ssh/id_dsa ((nil))
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-with-mic,password
debug3: preferred gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug3: Trying to reverse map address 192.168.1.75.
debug1: Unspecified GSS failure.  Minor code may provide more information
Unknown code krb5 195

debug1: Unspecified GSS failure.  Minor code may provide more information
Unknown code krb5 195

debug1: Unspecified GSS failure.  Minor code may provide more information
Unknown code krb5 195

debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/saguna/.ssh/identity
debug3: no such identity: /home/saguna/.ssh/identity
debug1: Offering public key: /home/saguna/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Trying private key: /home/saguna/.ssh/id_dsa
debug3: no such identity: /home/saguna/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
saguna@192.168.1.75's password: 
Run Code Online (Sandbox Code Playgroud)

小智 25

9/10 次是因为 ~/.ssh/authorized_keys 不在正确的模式下。

chmod 600 ~/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)

  • 如果这对某人不起作用,您还应该查看@Gilles 的回答。特别是 **home 和 `~/.ssh`** 目录不能被用户以外的任何人写入。 (6认同)
  • 仅供参考,我在 https://github.com/centic9/generate-and-send-ssh-key 创建了一个小脚本,它一次性运行必要的步骤,并确保所有文件/目录权限总是让我头疼。 .. (4认同)

Pat*_*aba 21

签入 /etc/ssh/sshd_config 以允许使用密钥进行身份验证。你应该有这样的东西,并确保没有注释这些行:

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile  .ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)

PS:修改文件后不要忘记重启sshd(/etc/init.d/sshd restart)

  • 也许你不明白评论。注释掉的行显示默认值。如果您想要默认值,则无需取消注释它们。如果您想覆盖默认值,只需取消注释该属性即可。 (2认同)

小智 8

我发现我的系统的问题是用户目录 (/home/username) 配备了错误的权限集。过去drwxr-x-w-和现在都需要drwxr-xr-x(只有所有者拥有写权限)。解决方案是使用 chmod:

sudo chmod 0755 /home/username
Run Code Online (Sandbox Code Playgroud)


Gil*_*il' 6

最常见的问题是服务器端的权限无效。检查您的主目录是否~/.ssh可供~/.ssh/authorized_keys除您之外的任何人写入(特别是它们不能是组可写的)。

如果这不是问题,请运行ssh -vvv server并查看客户对对话的看法。特别是,检查客户端是否正在向服务器尝试密钥。


Dmi*_*ich 5

我不是这里的专家,但也遇到过这样的问题,除了所有其他建议,这是我的两分钱。

有时ssh-copy-id将错误的密钥复制到远程服务器(如果您有多个密钥和/或密钥文件使用非默认名称,可能会发生这种情况)或者您的身份验证代理配置错误。

这是手册页的引用:

如果给出 -i 选项,则使用身份文件(默认为 ~/.ssh/id_rsa.pub),无论 ssh-agent 中是否有任何密钥。否则,如果这样: ssh-add -L 提供任何输出,它会优先使用身份文件。

所以基本上你想检查一下:

  • 您的系统身份验证代理(通常是 ssh-agent)会看到您打算使用的密钥(检查ssh-add -L输出)
  • ssh-copy-id相同的密钥复制到远程机器(只需使用密码登录远程服务器并检查 的内容~/.ssh/authorized_keys
    • 如果您在远程服务器上没有看到所需的密钥,您可以隐式地告诉ssh-copy-id要复制哪个密钥:ssh-copy-id -i ~/.ssh/some_public_key

希望有帮助。


jac*_*hab -2

问题是我在 /etc/ssh/ssh_config 中禁用了 RSAAuthentication