[root@server ~]# ssh-keygen -t rsa #之后一路回车
Generating public/private rsa key pair.
Enter fileinwhich 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:087zOwx6jrL5/TT1N9+CY+fmPdvIAcn3MyEHPK0Wwhg root@server.example.com
The key's randomart image is:
+---[RSA 3072]----+
| E |
| + . . |
| . o = . |
| . ...= |
| S . ++oo |
| +. .+oo.|
| .+oo..++|
| ...o.+*o+=O|
| o+oooo+O=oB|
+----[SHA256]-----+
[root@server ~]# ssh-copy-id node1.example.com #server端向node1分发密钥
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'node1.example.com (192.168.80.130)' can't be established.
ED25519 key fingerprint is SHA256:8/9KJPE9MmvW3tHXlBouijAhOshcqcqUX2ejOmS28tk.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? 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.example.com's password: #输入登录node1的密码
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'node1.example.com'"
and check to make sure that only the key(s) you wanted were added.
[root@server ~]# ssh-copy-id node2.example.com #server端向node2分发密钥
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'node2.example.com (192.168.80.131)' can't be established.
ED25519 key fingerprint is SHA256:8/9KJPE9MmvW3tHXlBouijAhOshcqcqUX2ejOmS28tk.
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:1: node1.example.com
Are you sure you want to continue connecting (yes/no/[fingerprint])? 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@node2.example.com's password: #输入登录node2的密码
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'node2.example.com'"
and check to make sure that only the key(s) you wanted were added.
测试
[root@server ~]# ssh node1.example.com #server端远程登录到node1端
Activate the web console with: systemctl enable--now cockpit.socket
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Fri Jul 5 07:34:02 2024 from 192.168.80.129
[root@node1 ~]# exit #已成功,注销
注销
Connection to node1.example.com closed.
[root@server ~]#
[root@server ~]# ssh node2.example.com #server端远程登录到node2端
Activate the web console with: systemctl enable--now cockpit.socket
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Fri Jul 5 07:34:21 2024 from 192.168.80.130
[root@node2 ~]# exit #已成功,注销后回到server端
注销
Connection to node2.example.com closed.
[root@server ~]#