How can I restart gpg-agent?

Some changes in the GnuPG configuration demands a gpg-agent restart / reboot (according to the doc), but... How can I do that? I tried gpg-agent restart, service gpg-agent restart, but did not succeed.


Solution 1:

With current GPG (2.1+), to stop gpg-agent you can use gpgconf --kill, like this:

gpgconf --kill gpg-agent

You shouldn’t need to manually restart it. GPG will restart it when it’s needed.

Solution 2:

My preferred way is with gpg-connect-agent reloadagent /bye. See gpg-connect-agent help /bye for a complete list of commands.

Solution 3:

gpg-agent is not a system-wide service but started once per user (thus, it is not managed by service). Although sometimes invoked by user's dotfiles or at least in Debian and derivatives also when X11 is started (and gpg-agent is installed) in /etc/X11/Xsession.d/90gpg-agent (to make sure a common gpg-agent is used by all GnuPG calls, no matter whether from a terminal or GUI applications); it is also started automatically by GnuPG when required. From man gpg-agent:

The agent is automatically started on demand by gpg, gpgsm, gpgconf, or gpg-connect- agent. Thus there is no reason to start it manually. In case you want to use the included Secure Shell Agent you may start the agent using:

gpg-connect-agent /bye

Usually, a simple killall gpg-agent (from a non-root shell) should be fine for terminating gpg-agent. You'll likely observe a slight delay when using GnuPG the next time, as gpg-agent is started again.

Solution 4:

On modern systemd-based Linux distros the gpg-agent is controlled by the userspace systemd.

You can check/start/stop it with the following commands (without sudo):

systemctl --user status gpg-agent
systemctl --user stop gpg-agent
systemctl --user start gpg-agent