Ssh – Import the SSH key as GPG sub-key to use for SSH authentication

gpgssh

I recently created a PGP key to sign my commits and it's working properly. I also discovered that gpg integrates better with my O.S. (Kubuntu) than ssh-agent.

I'm lazy and would like to avoid having to replace my SSH key in all the various servers I've access to.

Is there any option for me to import my existing SSH key as a subkey of my PGP key and then run gpg agent with ssh-agent support so that when I run ssh something it uses my subkey and uses gpg agent to ask for the passphrase?

Ideally I supply the passhprase only once, for my main PGP key and then whenever I commit or login through ssh, it uses the right one.

Is it possible? (I know they are different format, but that's really all I know)

Best Answer

All that you need:

export GPG_TTY=$(tty)
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
ssh-add -c -t 3600 ~/.ssh/id_rsa   # set the cache lifetime as 3600s

Then feel free to remove the files: mv ~/.ssh/id_rsa.* /path/to/backup.

Now you can do an SSH login for testing.

After all, remember to add the Environments to your profile, like .profile or ~/.bashrc.


(Ps:You can find the ssh key(in gpg format) exists in ~/.gnupg/private-keys-v1.d/ and with keygrip as its name, which can be used to be added as a subkey.

Reference:

https://incenp.org/notes/2015/gnupg-for-ssh-authentication.html

https://www.gnupg.org/documentation/manuals/gnupg/Invoking-GPG_002dAGENT.html

Related Question