ssh密钥的生成与使用

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

ssh密钥的⽣成与使⽤
1:如果系统是windows那么需要在linux系统上操作,系统是mac直接⽤命令窗⼝操作即可。

[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即可(如果是mac系统全局搜索就好,全局搜索快捷键:command + 空格,密钥⽂件默认存放位置或者 ~/.ssh 即可看到⽂件)
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+B*o. |
| oo.=EXO. |
+----[SHA256]-----+
密钥锁码在使⽤私钥时必须输⼊,这样就可以保护私钥不被盗⽤。

当然,也可以留空,实现⽆密码登录,这⾥密钥锁码设置为空。

完成上述步骤后,在 root ⽤户的家⽬录中⽣成了⼀个 .ssh 的隐藏⽬录,内含两个密钥⽂件,其中id_rsa 为私钥,id_rsa.pub 为公钥。

2.把公钥传输⾄远程服务器
这⾥的远程服务器是172.16.8.11
[root@localhost ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.8.11
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.16.8.11 (172.16.8.11)' can't be established.
ECDSA key fingerprint is SHA256:IpS8Vw0F/Yxece36yQ9KhoIuxHFjSi/Ect/WHGxw//k.
ECDSA key fingerprint is MD5:03:85:10:9a:21:75:d6:f1:7a:6e:fd:a8:08:c5:ef:59.
Are you sure you want to continue connecting (yes/no)? yes <== 是否继续连接,回答为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@172.16.8.11's password: <==输⼊远程主机的密码
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.16.8.11'"
and check to make sure that only the key(s) you wanted were added.。

相关文档
最新文档