Hello!
This is my first contribution to the GPG bug tracker. Please let me know if there is anything missing, and sorry if I missed an existing bug.
I am on macOS using brew's GPG:
gpg (GnuPG) 2.3.4 libgcrypt 1.10.0
GPG won't let me export a secret ssh key:
$ gpg --export-secret-ssh-key 17477E54BB15F155AB66CA72E8BC9929304AEAED gpg: key "17477E54BB15F155AB66CA72E8BC9929304AEAED" not found: Not a Keygrip
But it lets me export the same key as a public key:
$ gpg --export-ssh-key 17477E54BB15F155AB66CA72E8BC9929304AEAED ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC5RCHoVRB7rCs4WDbPXc9ak3oRqt48W1wOKM+JCXHxJaYB4i7rq9ZAvAUIvCQT8R05A+/f9pCEOUm/ZW14/isij7SBO3UExoX2OFddOcqdTFYyQFrUY98EX5XvNa/2aT7qS80bMptIDY8DAEmE4+cozvkHolWm3Erc56cZwaZN6Yt49gHQUoaq5Iy3qWdoLdzEcV6ke9MrvhV/rBJUwEqdgH1ENUBnbS5u/gmxSm9QVOhNf3Dl1HjsGsynX2Af2qu6Gcu6okRgM7ftbUd6Fh06lN/D3PHXtWnOUznyePo8vnZi0MKK4c8iM3lbK360JyseXHOBhyn5hbySmgnVDi6mIcddXIWxyr09uScSirc9c/sJjCmyfIddzNnGJ9x5kCznGsqnZDMlFId2gnonV8i8471gkwgGG2Put6/8wwtQJhGvgavS/+WNfhKBN0/V3qaLo0aaeNrW1KZDT8y/ZzucTD1iOlsuhNgNB/0CUU2de8ojJsDLcymcz7dvf3mV29M= openpgp:0x632A040F
Steps to reproduce:
- Generate a new key
- gpg --expert --edit-key <KEYID>
- addkey
- RSA (add your own capabilities)
- Enable only the A (Authenticate) capability
- Try to export it.
It could be that I am doing something wrong here, but the "not found" error does not help me understand it. Obviously the key exists if I am able to export the public version of it.
I considered that I may need to specify the subkey fingerprint to export the secret ssh key, so I tried to find the fingerprint:
$ gpg --list-secret-keys --with-subkey-fingerprint sec ed25519 2022-02-17 [SC] [expires: 2024-02-17] 17477E54BB15F155AB66CA72E8BC9929304AEAED uid [ultimate] Alexandre Viau ssb cv25519 2022-02-17 [E] [expires: 2024-02-17] 0B0FB91C5F9674BF5E2F0CA67A2C2C0F04F463F6 ssb rsa3072 2022-02-17 [A] 21DEE1DF6D759B8593EF8118B056AF8B632A040F
Then export the public key, that works:
$ gpg --export-ssh-key 21DEE1DF6D759B8593EF8118B056AF8B632A040F ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC5RCHoVRB7rCs4WDbPXc9ak3oRqt48W1wOKM+JCXHxJaYB4i7rq9ZAvAUIvCQT8R05A+/f9pCEOUm/ZW14/isij7SBO3UExoX2OFddOcqdTFYyQFrUY98EX5XvNa/2aT7qS80bMptIDY8DAEmE4+cozvkHolWm3Erc56cZwaZN6Yt49gHQUoaq5Iy3qWdoLdzEcV6ke9MrvhV/rBJUwEqdgH1ENUBnbS5u/gmxSm9QVOhNf3Dl1HjsGsynX2Af2qu6Gcu6okRgM7ftbUd6Fh06lN/D3PHXtWnOUznyePo8vnZi0MKK4c8iM3lbK360JyseXHOBhyn5hbySmgnVDi6mIcddXIWxyr09uScSirc9c/sJjCmyfIddzNnGJ9x5kCznGsqnZDMlFId2gnonV8i8471gkwgGG2Put6/8wwtQJhGvgavS/+WNfhKBN0/V3qaLo0aaeNrW1KZDT8y/ZzucTD1iOlsuhNgNB/0CUU2de8ojJsDLcymcz7dvf3mV29M= openpgp:0x632A040F
But once again, I can't export the private key:
$ gpg --export-secret-ssh-key 21DEE1DF6D759B8593EF8118B056AF8B632A040F gpg: key "21DEE1DF6D759B8593EF8118B056AF8B632A040F" not found: Not a Keygrip
The error says "not a keygrip", so I probably need to use a keygrip! Let's find it:
$ gpg --list-secret-keys --with-keygrip sec ed25519 2022-02-17 [SC] [expires: 2024-02-17] 17477E54BB15F155AB66CA72E8BC9929304AEAED Keygrip = 1DDF1E8CF981026EAD80AADAE683FD8E6EE816A2 uid [ultimate] Alexandre Viau ssb cv25519 2022-02-17 [E] [expires: 2024-02-17] Keygrip = 2CD5ACAEDBFB6A62B972DAFE150AB3E8C943404C ssb rsa3072 2022-02-17 [A] Keygrip = 2764D50D0AD3A7A2495B21AE5F35BD3E710B46C2
Yay, we have a keygrip, the exact thing the error message is asking for me! Let's use it:
$ gpg --export-secret-ssh-key 2764D50D0AD3A7A2495B21AE5F35BD3E710B46C2 gpg: key "2764D50D0AD3A7A2495B21AE5F35BD3E710B46C2" not found: Not a Keygrip
Ah, apparently its not a keygrip...