OpenSSH 私钥搞砸了:加载密钥:格式无效

OpenSSH 私钥搞砸了:加载密钥:格式无效

当尝试更改 SSH 私钥密码时,我从 ssh 收到以下错误消息:

Load key "/home/me/.ssh/id_rsa.pub": invalid format

密码加密仍然有效,并且我的密码是正确的,事实证明,当我尝试更改密码并输入错误的密码时,我得到

$ ssh-keygen -p -f id_rsa.broken
Enter old passphrase: 
Failed to load key id_rsa.broken: incorrect passphrase supplied to decrypt private key

但是,如果我输入正确的密码,我会得到:

$ ssh-keygen -p -f id_rsa.broken
Enter old passphrase: 
Failed to load key id_rsa.broken: invalid format

这就是为什么我确信新密码是正确的。我还尝试使用 OpenSSL 处理我的密钥,但出现很多错误(至少有更多详细信息):

openssl rsa -text -in id_rsa.broken -out id_rsa.openssl-decrypt
Enter pass phrase for id_rsa.broken:
unable to load Private Key
140674488831512:error:0D0680A8:asn1 encoding 
routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1199:
140674488831512:error:0D07803A:asn1 encoding 
routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:374:Type=RSA
140674488831512:error:04093004:rsa routines:OLD_RSA_PRIV_DECODE:RSA 
lib:rsa_ameth.c:121:
140674488831512:error:0D0680A8:asn1 encoding 
routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1199:
140674488831512:error:0D07803A:asn1 encoding 
routines:ASN1_ITEM_EX_D2I:nested asn1 
error:tasn_dec.c:374:Type=PKCS8_PRIV_KEY_INFO
140674488831512:error:0907B00D:PEM 
routines:PEM_READ_BIO_PRIVATEKEY:ASN1 lib:pem_pkey.c:141:

注意:这个问题的原作者看到了类似但不相同的错误:

140405067433728:error:0D07209B:asn1 encoding 
routines:ASN1_get_object:too long:crypto/asn1/asn1_lib.c:91:
140405067433728:error:0D068066:asn1 encoding 
routines:asn1_check_tlen:bad object 
header:crypto/asn1/tasn_dec.c:1100:
140405067433728:error:0D07803A:asn1 encoding 
routines:asn1_item_embed_d2i:nested asn1 
error:crypto/asn1/tasn_dec.c:274:Type=RSA
140405067433728:error:04093004:rsa routines:old_rsa_priv_decode:RSA 
lib:crypto/rsa/rsa_ameth.c:72:
140405067433728:error:0D07209B:asn1 encoding 
routines:ASN1_get_object:too long:crypto/asn1/asn1_lib.c:91:
140405067433728:error:0D068066:asn1 encoding 
routines:asn1_check_tlen:bad object 
header:crypto/asn1/tasn_dec.c:1100:
140405067433728:error:0D07803A:asn1 encoding 
routines:asn1_item_embed_d2i:nested asn1 
error:crypto/asn1/tasn_dec.c:274:Type=PKCS8_PRIV_KEY_INFO
140405067433728:error:0907B00D:PEM 
routines:PEM_read_bio_PrivateKey:ASN1 lib:crypto/pem/pem_pkey.c:86:

我的私钥看起来像这样,我看不出任何明显错误:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,somehexvaluewith16digits

someblockofcharacterswith24linesand64charactersperline
-----END RSA PRIVATE KEY-----

我不明白的是这把钥匙最初是如何搞砸的。我可以保证我更改密码时没有进行任何手动编辑。我很确定我用来编辑它的只是程序ssh-keygen

有人知道可能出了什么问题以及如何取回我的钥匙吗?当与已知主机建立 SSH 连接时,私钥似乎仍然有效。

相关内容