3

I have followed How to enable SSH access using a GPG key for authentication to enable SSH access using a GPG key for authentication.

$ gpg2 --expert --edit-key <KEY ID>
gpg> addkey
Please select what kind of key you want:
   (3) DSA (sign only)
   (4) RSA (sign only)
   (5) Elgamal (encrypt only)
   (6) RSA (encrypt only)
   (7) DSA (set your own capabilities)
   (8) RSA (set your own capabilities)
  (10) ECC (sign only)
  (11) ECC (set your own capabilities)
  (12) ECC (encrypt only)
  (13) Existing key
Your selection? 8

Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Sign Encrypt

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? s
Your selection? e
Your selection? a

Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Authenticate

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? q
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y
Really create? (y/N) y

sec  rsa2048/8715AF32191DB135
     created: 2019-03-21  expires: 2021-03-20  usage: SC  
     trust: ultimate      validity: ultimate
ssb  rsa2048/150F16909B9AA603
     created: 2019-03-21  expires: 2021-03-20  usage: E  
ssb  rsa2048/17E7403F18CB1123
     created: 2019-03-21  expires: never       usage: A  
[ultimate] (1). Brian Exelbierd

gpg> quit
Save changes? (y/N) y

Added enable-ssh-support to ~/.gnupg/gpg-agent.conf file.

Added Keygrip to ~/.gnupg/sshcontrol file.

$ gpg2 -K --with-keygrip
/home/bexelbie/.gnupg/pubring.kbx
------------------------------
sec   rsa2048 2019-03-21 [SC] [expires: 2021-03-20]
      96F33EA7F4E0F7051D75FC208715AF32191DB135
      Keygrip = 90E08830BC1AAD225E657AD4FBE638B3D8E50C9E
uid           [ultimate] Brian Exelbierd
ssb   rsa2048 2019-03-21 [E] [expires: 2021-03-20]
      Keygrip = 5FA04ABEBFBC5089E50EDEB43198B4895BCA2136
ssb   rsa2048 2019-03-21 [A]
      Keygrip = 7710BA0643CC022B92544181FF2EAC2A290CDC0E

$ echo 7710BA0643CC022B92544181FF2EAC2A290CDC0E >> ~/.gnupg/sshcontrol

Added the following to my .zshrc

export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent

The tutorial says:

First, you can run ssh-add -L to list your public keys and copy it manually to the remote host. You can also use ssh-copy-id. From this perspective, nothing has changed.

But ssh-add -L says The agent has no identities.

% ssh-add -L
The agent has no identities.

I have tried

% eval "$(ssh-agent -s)"
Agent pid 26756
% kill -9 26756
% gpg-connect-agent reloadagent /bye
OK
% systemctl --user restart gpg-agent
% systemctl restart ssh
% systemctl restart sshd
% ssh-add -L
The agent has no identities.

How to use a GPG key for SSH authentication says:

Restart the GPG agent:

sudo killall gpg-agent
gpg-agent --daemon --write-env-file ~/.gpg-agent-info --enable-ssh-support
source ~/.gpg-agent-info

....

If you see The agent has no identities, try the steps to restart the GPG agent from above.

But running the command has a different error.

% gpg-agent --daemon --write-env-file ~/.gpg-agent-info --enable-ssh-support
gpg-agent[29055]: WARNING: "--write-env-file" is an obsolete option - it has no effect
gpg-agent: a gpg-agent is already running - not starting a new one

What can I do?

2
  • Which version of GnuPG are you using? Commented Jan 4, 2022 at 0:45
  • I am using gpg (GnuPG) 2.2.19. However, the problem is solved. I just had to run ssh-keygen before running gpg --full-generate-key --expert (even though I am using gpg-agent and not ssh-agent). The primary key only allows Certify. Subkey allows Sign Encrypt Authenticate. Manually writing to ~/.gnupg/sshcontrol and ~/.gnupg/gpg-agent.conf did not work. I had to enable-ssh-support >> ~/.gnupg/gpg-agent.conf. Not sure why this weird behavior. But this is what I needed to do to get it working. Commented Jan 4, 2022 at 3:19

1 Answer 1

-1

Launch ssh-add -l from $HOME directory

1
  • What will that do? … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. Commented Jun 27, 2022 at 17:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .