CentOS系统SSH免密后依然需要输入密码(已解决)

1、问题

通过ssh-keygen -t rsa和ssh-copy-id -i node1操作后,免密登录依然需要输入密码。

[root@node1 ~]# ssh node1
The authenticity of host 'node1 (192.168.1.160)' can't be established.
ECDSA key fingerprint is SHA256:CzXPsWonK4Fxx8mQpRHXL1K8R8eqyQr+Zn95HGS8zQ4.
ECDSA key fingerprint is MD5:61:95:b5:57:d3:bb:d0:9d:bf:9c:e1:d4:40:4f:07:d6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node1,192.168.1.160' (ECDSA) to the list of known hosts.
root@node1's password: 

2、原因与解决办法

一般来讲失败的原因有两个:目录文件的权限和目录的属主。 (1)目录文件的权限 .ssh父目录的权限是755(我的是/root),.ssh目录权限是700,authorized_keys文件 600

[root@node1 ~]# chmod 755 /root
[root@node1 ~]# chmod 700 .ssh
[root@node1 ~]# chmod 600 .ssh/authorized_keys

(2)目录的属主 如果上面方法还没有解决问题,那可能是.ssh父目录的属主存在问题。

[root@node1 ~]# ls -al .ssh
total 12
drwx------   2 root root    80 Nov  3 10:07 .
drwxr-xr-x. 11 hdfs users 4096 Nov  3 09:38 ..
-rw-------   1 root root     0 Nov  3 10:06 authorized_keys
-rw-------   1 root root  1679 Nov  3 09:38 id_rsa
-rw-r--r--   1 root root   390 Nov  3 09:38 id_rsa.pub
-rw-r--r--   1 root root     0 Nov  3 10:07 known_hosts

这里发现.ssh父目录(..)的属主存在问题。

修改如下

[root@node1 ~]# chown -R root:root /root
[root@node1 ~]# ls -al .ssh
total 16
drwx------   2 root root   80 Nov  3 10:07 .
drwxr-xr-x. 11 root root 4096 Nov  3 09:38 ..
-rw-------   1 root root 1135 Nov  3 10:11 authorized_keys
-rw-------   1 root root 1679 Nov  3 09:38 id_rsa
-rw-r--r--   1 root root  390 Nov  3 09:38 id_rsa.pub
-rw-r--r--   1 root root    0 Nov  3 10:07 known_hosts
[root@node1 ~]# 

3、验证

[root@node2 ~]# ssh-copy-id -i node1
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@node1's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'node1'"
and check to make sure that only the key(s) you wanted were added.

[root@node2 ~]# ssh node1
Last login: Fri Nov  3 10:04:03 2017 from hadron
[root@node1 ~]# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值