使用ssh-keygen生产RSA密钥对并上传目标主机

保存文件名称,默认私钥保存在id_rsa,公钥保存在id_rsa.pub
命令一定要加-m PEM 不然生成出来的是OPENSSL密钥

:~$ ssh-keygen -m PEM
Generating public/private rsa key pair.
#密钥保存文件
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):
#密钥的密码,空表示没有密码
Enter passphrase (empty for no passphrase):
#确认密码
Enter same passphrase again:
+---[RSA 3072]----+
|        o o. ..  |
|       o + o..   |
|    . =   o o    |
|   + E * +   o   |
|  . = + S * . .  |
|   o o   * =  ..=|
|  . +     = . .B*|
|   . .   ...o.*.+|
|           =+= . |
+----[SHA256]-----+

查看

~$ ls ~/.ssh
id_rsa  id_rsa.pub known_hosts

上传目标主机

~$ ssh-copy-id -i ~/.ssh/id_rsa root@x.x.x.x
#服务端安装目录
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/root/.ssh/id_rsa.pub"
#日志信息告诉你它会过滤出已经安装的证书
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

Number of key(s) added: 1
#你可以直接使用以下命令连接服务器了
Now try logging into the machine, with:   "ssh 'root@x.x.x.x'"
and check to make sure that only the key(s) you wanted were added.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值