3

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.

7
  • 4
    You certainly did not re-encrypted a key without having the old passphrase... Aug 13, 2017 at 12:25
  • @HaukeLaging Probably encrypted the key file with a new key, then the garbage would make sense.
    – sebix
    Aug 13, 2017 at 19:43
  • 2
    Your question is self-contradictory: you write “a password that I since forgot”, and “I re-encrypted it with my current password”. You can't have re-encrypted without the original password. What command(s) did you run exactly? If you don't remember, you'll need to accept that you forgot the password, and use a new key. And even if you do remember which commands you ran, the key file is no use to you without the password. Aug 14, 2017 at 0:13
  • 1
    Anonymous editor: essentially changing a question is typically not okay. Although in the case of a closed, abandoned question, with the intent to make it reopenable, is maybe a border case. The best would be if you would register to the site, then you would ask this as a new question, by referencing this poor, closed one.
    – peterh
    Sep 27, 2017 at 19:06
  • @peterh: If you feel that way, why did you approve the edit? Sep 27, 2017 at 19:57

0

Browse other questions tagged .