![从 OSX 使用 RSA 公钥/私钥通过 SSH 访问 CentOS 5 服务器](https://linux22.com/image/555938/%E4%BB%8E%20OSX%20%E4%BD%BF%E7%94%A8%20RSA%20%E5%85%AC%E9%92%A5%2F%E7%A7%81%E9%92%A5%E9%80%9A%E8%BF%87%20SSH%20%E8%AE%BF%E9%97%AE%20CentOS%205%20%E6%9C%8D%E5%8A%A1%E5%99%A8.png)
我正在尝试使用 RSA 密钥(而不是密码)配置对 CentOS 服务器的 SSH 访问,但它拒绝接受密钥。以下是我到目前为止所做的:
在客户端机器上(OSX):
ssh-keygen -b 4096 -C "[email protected]" -t rsa
// no passphrase
在服务器上(CentOS 5):
cat id_rsa.pub >> ~/.ssh/authorized_keys2
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
chmod go-w ~/
// Added to /etc/ssh/sshd_config:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys2
// and finally restart sshd
/sbin/service sshd restart
回到尝试连接的客户端:
ssh [email protected] -v
debug1: Found key in /Users/jwood/.ssh/known_hosts:16
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
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/jwood/.ssh/identity
debug1: Offering public key: /Users/jwood/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Offering public key: /Users/jwood/.ssh/id_dsa
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: password
[email protected]'s password:
如您所见,它尝试使用公钥,但无法恢复为密码。配置中可能存在哪些问题导致这种情况?
谢谢,J
答案1
确保 authorized_keys2 文件的每个密钥占一行