根据之前的设置或网上的很多介绍,始终无法做到免密码登录,经过多次测试,最终解决:
使用root:
vi /etc/ssh/sshd_config
Protocol 2
PasswordAuthentication no
PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
service sshd restart
使用要免密码登录的用户执行:
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
chmod 644 authorized_keys
chmod 700 -R .ssh //设置免密码登录用户主目录下的隐藏目录.ssh
ssh localhost
报:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)
这个问题是因为SELinux被打开了,暂时关闭(重启恢复):
setenforce 0 //使用root执行
vi /etc/selinux/config
SELINUX=disabled