一、 客户端是linux
1.在客户端生成密钥对
[root@localhost ~]# ssh-keygen -t rsa <== 建立密钥对,-t代表类型,有RSA和DSA两种
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <==密钥文件默认存放位置,按Enter即可
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空
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:K1qy928tkk1FUuzQtlZK+poeS67vIgPvHw9lQ+KNuZ4 root@localhost.localdomain
The key’s randomart image is:
+—-[RSA 2048]——+
| +. |
| o . |
| . .O + |
| . . |
| S =+ |
| . =… |
| .oo =+o+ |
| ==o+Bo. |
| oo.=EXO. |
+——[SHA256]——-+
cat ~/.ssh/authorized_keys # 查看保存公钥
cat ~/.ssh/idrsa.pub #查看当前主机公钥
二、 客户端是mac
1 $ ssh- keygen #建立密钥对
2 Generating public/private rsa key pair.
3 Enter file in which to save the key (/Users/schacon/ . ssh/id rsa): #密钥文件默认存放位置,按Enter即可
4 Enter passphrase ( empty for no passphrase) :
5 Enter same passphrase again:
6 Your identification has been saved in /Users/ schacon/ .ssh/id rsa. #生成的私钥
7 Your public key has been saved in /Users/schacon/ . ssh/id_ rsa . pub . #生成的公钥
8 The key fingerprint is:
9 43: c5:5b:5f:b1:f1: 50:43:ad:20:a6 :92:6a:1f:9a:3a schacon@Wi kky ‘ sMacBookPro. local ,
**