linux多机器免密登录

环境:

三台Linux 服务器    

 IP                                   Release                         Hostname                                          

192.168.31.135              centos6.5                            HDFS

192.168.31.133              centos6.5                            HDFS-01

192.168.31.134              centos6.5                            HDFS-02

配置HDFS 无密连接HDFS-01、HDFS-02

[root@HDFS ~]# ssh-keygen -t rsa
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:
6b:f0:c3:1e:f3:bd:00:3b:50:cf:66:c6:d0:42:66:3d root@HDFS
The key's randomart image is:
+--[ RSA 2048]----+
|        +.       |
|       + .E      |
|        + ..     |
|       . *       |
|      o S B      |
|       = B       |
|        @ .      |
|       o * o     |
|        . . o.   |
+-----------------+

在 .ssh 目录下生成公钥和私钥:

[root@HDFS .ssh]# ll
total 8
-rw-------. 1 root root 1679 Oct  9 15:34 id_rsa
-rw-r--r--. 1 root root  391 Oct  9 15:34 id_rsa.pub

将公钥复制到需要免密连接的服务器上(HDFS-01、HDFS-02)

[root@HDFS .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
The authenticity of host '192.168.31.133 (192.168.31.133)' can't be established.
RSA key fingerprint is aa:0a:2f:20:c3:58:c5:00:da:8f:9d:ba:23:25:3e:ac.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.31.133' (RSA) to the list of known hosts.
[email protected]'s password: 
Now try logging into the machine, with "ssh '[email protected]'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

免密登录: ssh 192.168.31.133

[root@HDFS .ssh]# ssh 192.168.31.133
Last login: Tue Oct  9 15:29:22 2018 from hdfs
[root@HFDY-01 ~]# exit

猜你喜欢

转载自blog.csdn.net/weixin_42181917/article/details/82983345