Centos7 集群SSH无密码用户免密登录配置
例:配置集群1的A,B,C三台Centos7的test无密码用户免密登录
1,在A机器执行ssh-kengen生成秘钥,一路回车
[root@lms lms]# su - test [test@test ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:0jykURKZQMKvbEhlncm6Kef2ZH8mYwRUlYsdj1nzjZ0 root@lms The key's randomart image is: +---[RSA 2048]----+ | ...=.*=o.. | | .+ *oo o o | | o.o . + B o + .| | . ... B = . o E | |.o .o + S | |..++ o . | | .+ o. | | oo .+ o | | . ....= | +----[SHA256]-----+ [test@test ~]#
2,在该用户的家目录会生成一个.ssh目录,进入该目录,拷贝一份公钥(id_rsa.pub),并命名为 authorized_keys
[test@test ~]# cd .ssh/ [test@test .ssh]# pwd /home/test/.ssh [test@test .ssh]# ll 总用量 12 -rw-------. 1 test root 1675 6月 29 17:01 id_rsa -rw-r--r--. 1 test root 390 6月 29 17:01 id_rsa.pub -rw-r--r--. 1 test root 1042 6月 6 10:08 known_hosts [test@test .ssh]# [test@test .ssh]# cp id_rsa.pub authorized_keys [test@test .ssh]#
3,在B,C机器的test用户下执行ssh-keygen
4,将 id_rsa,id_rsa.pub,authorized_keys拷贝至B,C机器的/home/test/.ssh下即可(使用root用户拷贝)
[root@test .ssh]# scp authorized_keys id_rsa id_rsa.pub root@10.10.10.1:/home/test/.ssh/
5,测试,切换test用户:su - hdfs,执行ssh test@10.10.10.2
[root@test ~]# su - test [test@test ~]# [test@test ~]# ssh test@10.10.10.1