生成公钥和私钥
执行命令:ssh -keygen -t rsa
就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)
将公钥拷贝到要免密登录的目标机器上
执行命令:ssh-copy-id hadoop131
效果
[root@localhost ~]# 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:8T6unfKR17oRUgZoroaWhT89ihZQoj7ugsM2IyvryB4 root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| .. |
| . . o . |
| . o . o. o |
|. . . . .o o |
|. . = oS o . |
| o = = o. o o |
|+E.. + o .= o . |
|O*. o . .o = o |
|%Oo. .+= o. |
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id root@hadoop131
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'hadoop131 (192.168.15.131)' can't be established.
ECDSA key fingerprint is SHA256:FPygJWbfLJ3M5RHZLVRgKmtRhQSpIShAU4m9Wq0C3c0.
ECDSA key fingerprint is MD5:9b:35:f5:de:01:80:f9:e9:e2:70:17:72:29:60:4f:24.
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@hadoop131's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'hadoop131'"
and check to make sure that only the key(s) you wanted were added.
[root@localhost ~]# ssh root@hadoop131
Last login: Sun Jul 4 21:27:38 2021 from 192.168.15.1
[root@localhost ~]# ll
总用量 4
-rw-------. 1 root root 1427 5月 16 23:26 anaconda-ks.cfg
drwxr-xr-x. 3 root root 17 5月 16 23:57 install
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:8d:ae:3b brd ff:ff:ff:ff:ff:ff
inet 192.168.15.131/24 brd 192.168.15.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::5368:7f7e:f9a4:13f0/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@localhost ~]# exit
登出
Connection to hadoop131 closed.
在视频里学到的记录下