I have lost access to my ~/.ssh/id_dsa
file (OpenSSH private key file in DSA algorithm), due to forgetting the passphrase.
But, originally, I have had it imported into gpg-agent
and protected it with a gpg-agent passphrase, which I do know. And the private key is still working fine under gpg-agent
even now, although I now desire to reconstruct the OpenSSH private key file using what is stored in gpg-agent
.
Using gpg-connect-agent
tool, with the following sequence of commands, I think am able to extract the private key (in hex/ascii format), though I don't know how to reconstruct it to the original OpenSSH private key file format:
- Start
gpg-connect-agent
with--hex
option. - In the
>
prompt, get the hex ID of the key usingkeyinfo --ssh-list
command (to be precise it's the third field that gives the hex ID of the key). - In the
>
prompt, executekeywrap_key --export
. - In the
>
prompt, executeexport_key <enter hex ID from step 2>
orexport_key --openpgp <enter hex ID from step 2>
.
Now, after prompting for the passphrase, receiving it and confirming it, gpg-connect-agent
tool displays a few dozen lines of hex & ascii codes, which I highly suspect to be my original imported ssh private key.
Then, it displays OK
, surely implying the operation was successful.
Assuming what it displayed is indeed my ssh private key (as per "help export_key", what was dumped on the screen is aeswrap-128 encrypted version of the key; most likely encrypted with my known gpg-agent passphrase), some help on how to convert that info into traditional ssh private key format would be much appreciated (a perl/python/shell/C program to do it would be a bonus!).