从私钥生成公钥 ssh 密钥 [英] Generate public ssh key from private key
问题描述
我有私人 ssh (id_rsa) 密钥.
I have private ssh (id_rsa) key.
我如何从中生成公钥?
推荐答案
选项 -y
输出公钥.来自 ssh-keygen
命令的 linux 手册:
The option -y
outputs the public key. From the linux manual for the ssh-keygen
command:
-y
---- 此选项将读取一个私有的 OpenSSH 格式文件并打印一个标准输出的 OpenSSH 公钥.
-y
---- This option will read a private OpenSSH format file and print an OpenSSH public key to stdout.
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
作为旁注,公钥的注释丢失了.我有一个需要评论的网站(Launchpad?),所以您需要编辑 ~/.ssh/id_rsa.pub 并将评论附加到第一行,评论和关键数据之间有一个空格.下面显示了一个示例公钥.
As a side note, the comment of the public key is lost. I've had a site which required the comment (Launchpad?), so you need to edit ~/.ssh/id_rsa.pub and append a comment to the first line with a space between the comment and key data. An example public key is shown truncated below.
ssh-rsa AAAA..../VqDjtS5 ubuntu@ubuntu
如果您想要以脚本方式添加评论并将公钥添加到您的 authorized_keys
文件中,您可以这样做...
If you want a scripted way to add a comment and also add the pubkey to your authorized_keys
file, you can do...
ssh-keygen -y -f ~/.ssh/id_rsa | \
sed 's/$/ comment-goes-here/' | \
tee ~/.ssh/id_rsa.pub | \
tee -a authorized_keys
这篇关于从私钥生成公钥 ssh 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!