先看这篇帖子: http://www.linuxproblem.org/art_9.html 其中的最下面的 note 要注意: Depending on your version of SSH you might also have to do the following changes:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640

如果还是提示要密码. 尝试看看 log

sudo grep -ir ssh /var/log/*

我的机器上遇到这个 error:

/var/log/secure:Jun 20 19:07:54 CT53-64-BASE sshd[28890]: \
Authentication refused: bad ownership or modes for directory /disk1/home/nick/

可以这样来 fix:

chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

 

为什么有 authorized_keys 和 authorized_keys2?

In OpenSSH prior to version 3, the sshd man page used to say: The $HOME/.ssh/authorized_keys file lists the RSA keys that are permitted for RSA authentication in SSH protocols 1.3 and 1.5 Similarly, the $HOME/.ssh/authorized_keys2 file lists the DSA and RSA keys that are permitted for public key authentication (PubkeyAuthentication) in SSH protocol 2.0.The release announcement for version 3 states that authorized_keys2 is deprecated and all keys should be put in the authorized_keys file.