Openssl
如何將 RFC4716 私鑰轉換為 PEM 私鑰?
如何在 ubuntu 20.04 中將 RFC4716 私鑰轉換為 PEM 私鑰?
對於我們的項目,我們在執行最新 openssh 軟體的設備上生成了 ssh 密鑰。JSch 抱怨身份驗證:
異常 com.jcraft.jsch.JSchException:身份驗證失敗
經過大量研究,包括建構一個最小的 git 客戶端,我們發現我們的其他關鍵文件有一個小的變化。標題不是以
————開始 RSA 私鑰——
但它始於
—–開始 OPENSSH 私鑰—–
顯示,該密鑰被格式化為新的預設 RFC4716 格式。
我在這裡有同樣的問題,但我想使用我的原始密鑰而不是重新生成一個。而且我不想使用像 PuTTY 這樣的 GUI 應用程序。我想在腳本中轉換它。
我嘗試了幾次嘗試,但這些都不是:
ssh-keygen -f id_rsa -m 'PEM' -e ssh-keygen -f id_rsa -e -m pem # I got PUBLIC KEY instead of private key openssl rsa -in ~/.ssh/id_rsa -outform pem openssl rsa -in id_rsa -pubout -out id_rsa.pub.pem openssl rsa -in ~/.ssh/id_rsaunable to load Private Key # unable to load Private Key # 139920849113728:error:0909006C:PEM routines:get_name:no start line:../crypto/pem/pem_lib.c:745:Expecting: ANY PRIVATE KEY
我該如何轉換它?
$ cat /tmp/test -----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn NhAAAAAwEAAQAAAYEArKk9jKvP/kwZq5GAog449OK5LzjppL5DbQhlJcqntzqu88+6WDHr lQM0IKyHgEkRDim8MrmisK2eIJrmj99STJEBPu7jgJ0q2ASToSeFiU8FB+yrV9ZmelwJ7f 1rD5vp3TlROAc08pIKb2YVHE4KfLzAncGXVETldTuGDAHgXQWIlhZDBGbkt8pwM/Kt10j4 t7snCGKNWm8c9K943Tv3J+okI+vdv3V5a2dfoCW+9cnNE57jotE/LTli5CwuxFcX5zc1ON i/l0opxWAfhi4sCZBiaMnMfSX9kvYNl0cnaIRvzB3/CoSkxq9OJicQ2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jiri@t500' Enter new passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved with the new passphrase. $ cat /tmp/test -----BEGIN RSA PRIVATE KEY----- MIIG5QIBAAKCAYEArKk9jKvP/kwZq5GAog449OK5LzjppL5DbQhlJcqntzqu88+6 WDHrlQM0IKyHgEkRDim8MrmisK2eIJrmj99STJEBPu7jgJ0q2ASToSeFiU8FB+yr V9ZmelwJ7f1rD5vp3TlROAc08pIKb2YVHE4KfLzAncGXVETldTuGDAHgXQWIlhZD BGbkt8pwM/Kt10j4t7snCGKNWm8c9K943Tv3J+okI+vdv3V5a2dfoCW+9cnNE57j otE/LTli5CwuxFcX5zc1ONi/l0opxWAfhi4sCZBiaMnMfSX9kvYNl0cnaIRvzB3/ CoSkxq9OJicQ2dDtXVu1LUvUrtHlabfthPq2UttHzwZWEVxR5ZYfW3v7hXgc5MrO MabffAu9ALs7eDv+3gnVNbp1Qv5Jl9L+R9VXO7OVxmWhPGrLlVZJr078rNfZBLt4 UEkiM9kswF0w+IVdUYm/VBJBSgfqCSo1xXxy9u8zzywqTn6/MW0zInF5nxcfBb8z omZUEmJeoZnWlGN9AgMBAAECggGBAKRYr3JvtBo8+444gDVAzmwiRtyxEowyYmGt RQH05TFeVVtTle8PDUuYcgzLzGqKogZWKYIq+rWrfMFSUDYP/vlMaOAraTdp4ncd 3BvgT5ZENei2GN4SARdk9jqnJjoEUVW2kh1/lqFx6ybgByYbDpZu3/UJaW7X6YVu NAjH3HUOqFUcOYw+GGTs92IrE9fA6KWSKfQsQpoa+3fYcnY69uXyU5Yxk7ADNKDM E9SPOTYhcOfFLK40+Cqm3f+MIrPWpSRO0Dcselcq/YpxdjmcaXVnVj/XqTGQwCn8 akCtgjarcaOkw5zO/UN1aphzCgojhH0HzV67ufG2alO1BYz5Hd1dyPX8itdDOUcT 6x1FRoiFkmvkbTVXl3FMJynzmPzuHRnmHrolhNy8ZeaE63I27TDDausddWQ7Pn03 LFazwJKYvCoxWBlT+8bMmiY2ACC5iNi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