第一步:执行 ssh-keygen -t rsa 然后一路回车就行
[root@node1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:hhzQUPVJcicy8fYOBfe2CKOwWHZeXc6WrHJDh4inbcw root@node1
The key's randomart image is:
+---[RSA 2048]----+
| o+..*.= o . |
| .. X O B . |
| = o @ = X |
| = B X * * . |
| . + S E * . |
| . . = . |
| . |
| |
| |
+----[SHA256]-----+
第二步:执行
加入授权
- ssh-copy-id -i root@lky01
- ssh-copy-id -i root@lky03
- ssh-copy-id -i root@lky02
[root@node1 ~]# ssh-copy-id -i root@node1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'node1 (fe80::5356:86a3:8f58:cbb6%ens33)' can't be established.
ECDSA key fingerprint is SHA256:DhM0amAseMWoNKULVENh5BJTreWedQPCVeLBPJBZMDA.
ECDSA key fingerprint is MD5:ad:a3:f3:2f:1b:8a:0a:05:05:c1:d5:42:01:27:38:4f.
Are you sure you want to continue connecting (yes/no)? yes
/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 'root@node1'"
and check to make sure that only the key(s) you wanted were added.
第二台机器执行同样的操作
如果配置不成功的话可以看看自己的映射有没有配置
配置映射:
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.172.110 node1
192.168.172.120 node2
192.168.172.130 node3
测试
[root@node1 ~]# ssh node2
Last login: Sat Oct 31 03:07:08 2020 from 192.168.172.1
[root@node2 ~]#