1、生成公钥
首先检查主机是否存在公钥:
进入./ssh目录,查询是否存在 id_rsa 和 id_rsa.pub(公钥)。
[root@server1 ~]# cd .ssh/
[root@server1 .ssh]# ll
总用量 16
-rw-r--r-- 1 root root 802 5月 22 10:35 authorized_keys
-rw------- 1 root root 1675 5月 22 10:34 id_rsa
-rw-r--r-- 1 root root 394 5月 22 10:34 id_rsa.pub
-rw-r--r-- 1 root root 522 5月 20 16:31 known_hosts
如果公钥不存在,需要生成公钥:
使用命令 ssh-keygen 生成公钥,在后续的回显中一路Enter
[root@host199 ~]# ssh-keygen
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:2CQOB8XnJktJ