测试环境的es集群中有两个节点需要跑一个脚本,前提需要做ssh免秘钥登录,但是做了免秘钥后,发现登录还需要输入密码。
如下图:
[root@es01 .ssh]# ssh 'elastic@172.0.0.52'
elastic@172.0.0.52's password:
[root@es01 .ssh]# ll
总用量 12
-rw------- 1 root root 1675 8月 3 20:09 id_rsa
-rw-r--r-- 1 root root 391 8月 3 20:09 id_rsa.pub
-rw-r--r-- 1 root root 172 8月 3 20:09 known_hosts
首先去查看系统的日志文件
tail /var/log/secure -n 20
发现问题的所在:Authentication refused: bad ownership or modes for file。
从字面上可以看出是目录的属主和权限配置不当,查找资料得知:ssh不希望home目录和~/.ssh目录对组有写权限。
查看elastic的家目录发现权限为777
[root@es01 .ssh]# cd /home/
[root@es01 home]# ll
总用量
drwxrwxrwx elastic elastic 月 : elastic
drwxr-xr-x ghl ghl 月 elasticsearch_exporter-1.0.4rc1.linux-amd64
drwx------. ghl ghl 月 ghl
drwxr-xr-x 月 : node_exporter-0.18.1.linux-amd64
通过下面几条命令修改其家目录和.ssh权限。
chmod g-w /home/elastic
chmod 700 /home/elastic/.ssh
chmod 600 /home/elastic/.ssh/authorized_keys
然去登录,就不用再输入密码了。
[root@es01 home]# chmod 700 elastic
[root@es01 home]# ll
总用量 4
drwx------ 8 elastic elastic 4096 8月 3 20:04 elastic
drwxr-xr-x 2 ghl ghl 152 8月 17 2018 elasticsearch_exporter-1.0.4rc1.linux-amd64
drwx------. 2 ghl ghl 59 3月 5 2018 ghl
drwxr-xr-x 2 3434 3434 69 8月 3 18:57 node_exporter-0.18.1.linux-amd64
[root@es01 home]# ssh 'elastic@172.0.0.52'
Last login: Sat Aug 3 20:03:22 2019
[elastic@es01 ~]$ exit
登出
Connection to 172.0.0.52 closed.
[root@es01 home]#