When attempting to change my SSH private key passphrase, I get the following error message from ssh:
Load key "/home/me/.ssh/id_rsa.pub": invalid format
The password encryption still works and my password is correct, evidenced by the fact that when I try to change the password and enter a wrong password, I get
$ ssh-keygen -p -f id_rsa.broken
Enter old passphrase:
Failed to load key id_rsa.broken: incorrect passphrase supplied to decrypt private key
However, if I enter the correct password, I get:
$ ssh-keygen -p -f id_rsa.broken
Enter old passphrase:
Failed to load key id_rsa.broken: invalid format
That's why I'm sure that the new password is correct. I also tried to process my Key using OpenSSL, but I get a lot of errors (at least with more detail):
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:
NOTE: The original author of this question saw similar, but not identical, errors:
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:
My private key looks like this, and I can not see anything obviously wrong:
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,somehexvaluewith16digits
someblockofcharacterswith24linesand64charactersperline
-----END RSA PRIVATE KEY-----
What I don't get is how this key got screwed up in the first place. I can guarantee that I did not do any manual editing when I changed my password. I'm pretty sure that all I ever used to edit it was the ssh-keygen
program.
Does anyone have an idea what could have gone wrong and how to get my key back? The private key still appears to work when making SSH connections with known hosts.