我正在尝试在 CentOS 5.4 上设置无密码 SSH 登录:
客户端仍然提示输入密码。我错过了什么?
谢谢。
编辑:按照建议检查 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)
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)
小智 8
我发现我的系统的问题是用户目录 (/home/username) 配备了错误的权限集。过去drwxr-x-w-
和现在都需要drwxr-xr-x
(只有所有者拥有写权限)。解决方案是使用 chmod:
sudo chmod 0755 /home/username
Run Code Online (Sandbox Code Playgroud)
最常见的问题是服务器端的权限无效。检查您的主目录是否~/.ssh
可供~/.ssh/authorized_keys
除您之外的任何人写入(特别是它们不能是组可写的)。
如果这不是问题,请运行ssh -vvv server
并查看客户对对话的看法。特别是,检查客户端是否正在向服务器尝试密钥。
我不是这里的专家,但也遇到过这样的问题,除了所有其他建议外,这是我的两分钱。
有时ssh-copy-id
将错误的密钥复制到远程服务器(如果您有多个密钥和/或密钥文件使用非默认名称,可能会发生这种情况)或者您的身份验证代理配置错误。
这是手册页的引用:
如果给出 -i 选项,则使用身份文件(默认为 ~/.ssh/id_rsa.pub),无论 ssh-agent 中是否有任何密钥。否则,如果这样: ssh-add -L 提供任何输出,它会优先使用身份文件。
所以基本上你想检查一下:
ssh-add -L
输出)
ssh-copy-id
相同的密钥复制到远程机器(只需使用密码登录远程服务器并检查 的内容~/.ssh/authorized_keys
)
ssh-copy-id
要复制哪个密钥:ssh-copy-id -i ~/.ssh/some_public_key
希望有帮助。