保存文件名称,默认私钥保存在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.