SSH密钥使您无需密码即可登录服务器。本指南介绍了如何使用Linux,Mac或Windows工作站以OpenSSH格式创建SSH密钥。
使用OpenSSH创建SSH密钥
按照以下步骤使用OpenSSH程序创建一个SSH密钥。
使用以下参数用ssh-keygen
生成密钥:
- 使用-t RSA参数生成RSA格式密钥
- 要获得更安全的4096-bit密钥,请使用-b 4096参数
- 要输入注释,请使用-C [comment]参数
例如:
$ ssh-keygen -t rsa -b 4096 -C "Example comment"
按ENTER键将键保存到默认位置,默认情况下,密钥存储在~/.ssh目录中,
Generating public/private rsa key pair.
Enter file in which to save the key (/home/example_user/.ssh/id_rsa):
请输入密钥的密码,
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
生成,并保存你的密钥。
Your identification has been saved in /home/example_user/.ssh/id_rsa.
Your public key has been saved in /home/example_user/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:J3gbQu5GcqB8/9UXwhjYGXJrFSrb1jJJTEBwpaqF/p0 Example comment
The key's randomart image is:
+---[RSA 4096]----+
| .o=o= o. |
| . O * |
| . . + X |
| . . = o * * |
| o + O S O + . |
| o O o * + . . |
| o + . . . . |
| o o o . |
| . E |
+----[SHA256]-----+
查看文件的内容。
Mac和Linux:
$ cat /home/example_user/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAA
...
...
...
B31qRacQThmVw== Example comment
windows :
C:> type C:Usersexample_user.sshid_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAA
...
...
...
B31qRacQThmVw== Example comment
相关文章