우분투 20.04에서 RFC4716 개인 키를 PEM 개인 키로 변환하는 방법은 무엇입니까?
우리 프로젝트에서는 최신 openssh 소프트웨어를 실행하는 장치에서 SSH 키를 생성합니다. JSch는 인증에 대해 불평합니다.
예외 com.jcraft.jsch.JSchException: 인증 실패
최소 git 클라이언트 구축을 포함한 많은 연구 끝에 우리는 다른 주요 파일에서 작은 변경 사항을 발견했습니다. 제목이 다음으로 시작하지 않습니다.
—–RSA 개인 키 시작—–
하지만 시작은
——SSH 개인 키 열기 시작——
키가 새로운 기본 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
어떻게 변환할 수 있나요?
답변1
$ cat /tmp/test
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEArKk9jKvP/kwZq5GAog449OK5LzjppL5DbQhlJcqntzqu88+6WDHr
lQM0IKyHgEkRDim8MrmisK2eIJrmj99STJEBPu7jgJ0q2ASToSeFiU8FB+yrV9ZmelwJ7f
1rD5vp3TlROAc08pIKb2YVHE4KfLzAncGXVETldTuGDAHgXQWIlhZDBGbkt8pwM/Kt10j4
t7snCGKNWm8c9K943Tv3J+okI+vdv3V5a2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gI/1ONDG3ndXgn8cFkLdSnF2Y
1yWVGKN2wVIFLjAAAACWppcmlAdDUwMAE=
-----END OPENSSH PRIVATE KEY-----
$ ssh-keygen -p -f /tmp/test -m PEM
Key has comment '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/UN1aphzC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