CentOS上实现SSH免密登录

实现node1到node2的 ssh免密登录步骤如下

1.生成秘钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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:
SHA256:rkz4se9E84W3at6v/V2HspuvUsruZX79vMuRIigPcHQ root@manage01
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| . E |
| . . . |
| . .S . o |
| .oo o.o.. ..|
| . oooo.+=..+o|
| + =+ =*.=+.*|
| =oo*=.OB+=O|
+----[SHA256]-----+

2.秘钥传送至远程主机

1
2
3
4
5
6
ssh-copy-id -i ~/.ssh/id_rsa.pub <node2 IP地址>
root@192.168.3.3's password:
Now try logging into the machine, with "ssh '192.168.3.3'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.

3.尝试登录

1
ssh root@192.168.3.3