I'm wondering what would be the best way to start gpg-agent at startup in order for my Yubikey to work with ssh. I tried adding gpg-agent -q /bye to my .bashrc with a check if the process was already running, if not then it ran that command. It starts gpg-agent, and ssh-add -l does list the GPG keys from my Yubikey, but my public key is not being read by gpg-agent when I ssh to an host. I then have to kill and restart and sometimes re-export the $SSH_AUTH_SOCK variable.
Now I'm trying it with a user defined systemd unit file, which seems to work as long as I have this export in my .bash_profile: export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/gnupg/S.gpg-agent.ssh. Below is the systemd unit file, I enabled it with systemctl --user enable gpg-agent.service
[Unit] Description=GnuPG Agent IgnoreOnIsolate=true [Service] Type=forking Environment=SSH_AUTH_SOCK=%t/gnupg/S.gpg-agent.ssh ExecStart=/usr/bin/gpg-agent --homedir %h/.gnupg --enable-ssh-support --daemon ExecStartPost=/usr/bin/systemctl --user set-environment SSH_AUTH_SOCK=${SSH_AUTH_SOCK} ExecStop=/usr/bin/gpg-agent /bye [Install] WantedBy=default.target
This is in my gpg-agent.conf:
enable-ssh-support default-cache-ttl 120 max-cache-ttl 300
I can't really find a documented way to do this, it all seem to be done with own inventions. So this is not really a bug, unless of course this is indeed nowhere defined. Then some official documentation would be nice. The best stuff I found to set gpg-agent up with a Yubikey are these: