bash Openssh 私钥转 RSA 私钥

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54994641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:05:59  来源:igfitidea点击:

Openssh Private Key to RSA Private Key

bashmacossshrsaopenssh

提问by Eleanor

(I am using MAC)

(我正在使用MAC)

My id_rsa starts with

我的 id_rsa 以

-----BEGIN OPENSSH PRIVATE KEY-----

but I expect it to starts with

但我希望它以

-----BEGIN RSA PRIVATE KEY-----

I have send my id_rsa.pub to server administrator to get the access to server, so I don't want to generate a new key.

我已将我的 id_rsa.pub 发送给服务器管理员以获取对服务器的访问权限,因此我不想生成新密钥。

  1. Is there any way that I can transfer my id_rsa which is a openssh private key to a RSA private key? (command please.)

  2. If I can transfer, do I also need to transfer id_rsa.pub? (command please.) It seems id_rsa.pub doesn't have a header like id_rsa, so I am not sure if I should also transfer this.

  1. 有什么方法可以将我的 id_rsa(它是 openssh 私钥)转移到 RSA 私钥?(请命令。)

  2. 如果可以转让,是否还需要转让id_rsa.pub?(请命令。)似乎 id_rsa.pub 没有像 id_rsa 这样的标题,所以我不确定我是否也应该传输它。

Thank you!

谢谢!

回答by Tad M.

You have an OpenSSH format key and want a PEM format key. It is not intuitive to me, but the suggested way to convert is by changing the password for the key and writing it in a different format at the same time. The command looks like this:

您有一个 OpenSSH 格式的密钥并且想要一个 PEM 格式的密钥。这对我来说并不直观,但建议的转换方法是更改​​密钥的密码并同时以不同的格式写入。该命令如下所示:

ssh-keygen -p -N "" -m pem -f /path/to/key

ssh-keygen -p -N "" -m pem -f /path/to/key

It will change the file in place, so make a backup of your current key just in case. -N ""will set the passphrase as none. I haven't tested this with a passphrase.

它将就地更改文件,因此请备份您当前的密钥以防万一。-N ""将密码设置为无。我没有用密码测试过这个。

The public key should be fine as is.

公钥应该没问题。

For the full explanation of the above command, see the -m option here: https://man.openbsd.org/ssh-keygen#m

有关上述命令的完整说明,请参阅此处的 -m 选项:https: //man.openbsd.org/ssh-keygen#m