Sample Header Ad - 728x90

systemd keeps restarting gpg-agent, even though gpg-agent.service and gpg-agent*.socket are masked

1 vote
1 answer
345 views
**Goal: I am trying to kill gpg-agent** (on Debian 12, if that matters) **and keep it dead forever.** --- #### Aside: Why? Because I just finished setting up GPG agent forwarding to my SSH server. Tried a few guides without success until I found [this one](https://benjamintoll.com/2023/06/07/on-gpg-agent-forwarding/) , which suggests:
$ gpg-connect-agent KILLAGENT /bye
on the remote host. With that, GPG agent forwarding finally works... --- ...but if I log in from another client (one that _doesn’t_ forward its gpg-agent socket to the remote host), then **systemd starts gpg-agent all over again**:
# Killing gpg-agent ---------------------------------------------
$ ssh 
$ gpg-connect-agent KILLAGENT /bye
OK closing connection
$ exit
logout
Connection to  closed

# Logging in with GPG socket forwarding: gpg-agent stays dead ---
$ ssh 
$ pgrep gpg-agent
# 👌 no output
$ gpg --list-secret-keys
/home/rlue/.config/gnupg/pubring.kbx
------------------------------------
sec   rsa3072/...     # 🎉 it works!
$ exit
logout
Connection to  closed

# Logging in from another client: gpg-agent is back -------------
$ ssh 
$ pgrep gpg-agent
17077  # 🤬 bad systemd!
### How do you know it’s systemd?
$ pstree --show-parents --show-pids $(pidof gpg-agent)
systemd(1)---systemd(663)---gpg-agent(17077)
### Which is puzzling because... This is all happening after running:
$ systemctl --user mask --now gpg-agent.service gpg-agent.socket gpg-agent-ssh
.socket gpg-agent-extra.socket gpg-agent-browser.socket
$ systemctl --user daemon-reload
I’ve even rebooted (see Uptime in the final section.) For reference, here is the status of all user systemd units:
$ systemctl --user list-unit-files
UNIT FILE                                    STATE     PRESET
app-print\x2dapplet@autostart.service        generated -
at-spi-dbus-bus.service                      static    -
dbus.service                                 static    -
dcim-transfer.photein.service                disabled  enabled
dcim-transfer.xferase.service                disabled  enabled
dconf.service                                static    -
dirmngr.service                              static    -
glib-pacrunner.service                       static    -
gnubiff.service                              enabled   enabled
gpg-agent.service                            masked    enabled
pipewire-pulse.service                       enabled   enabled
pipewire.service                             enabled   enabled
pk-debconf-helper.service                    static    -
shpool.service                               enabled   enabled
ssh-agent.service                            static    -
systemd-exit.service                         static    -
systemd-tmpfiles-clean.service               static    -
systemd-tmpfiles-setup.service               disabled  enabled
wireplumber.service                          enabled   enabled
wireplumber@.service                         disabled  enabled
xdg-desktop-portal-gtk.service               static    -
xdg-desktop-portal-rewrite-launchers.service enabled   enabled
xdg-desktop-portal.service                   static    -
xdg-document-portal.service                  static    -
xdg-permission-store.service                 static    -
xferase.service                              disabled  enabled
app.slice                                    static    -
background.slice                             static    -
session.slice                                static    -
dbus.socket                                  static    -
dirmngr.socket                               enabled   enabled
gpg-agent-browser.socket                     masked    enabled
gpg-agent-extra.socket                       masked    enabled
gpg-agent-ssh.socket                         masked    enabled
gpg-agent.socket                             masked    enabled
pipewire-pulse.socket                        enabled   enabled
pipewire.socket                              enabled   enabled
pk-debconf-helper.socket                     enabled   enabled
shpool.socket                                enabled   enabled
basic.target                                 static    -
bluetooth.target                             static    -
default.target                               static    -
exit.target                                  static    -
graphical-session-pre.target                 static    -
graphical-session.target                     static    -
paths.target                                 static    -
printer.target                               static    -
shutdown.target                              static    -
smartcard.target                             static    -
sockets.target                               static    -
sound.target                                 static    -
timers.target                                static    -
xdg-desktop-autostart.target                 static    -
systemd-tmpfiles-clean.timer                 disabled  enabled

54 unit files listed.
What gives? Any pointers would be deeply, deeply appreciated. ### OS & other details
$ neofetch
       _,met$$$$$gg.          rlue@
    ,g$$$$$$$$$$$$$$$P.       -------------
  ,g$$P"     """Y$$.".        OS: Debian GNU/Linux 12 (bookworm) x86_64
 ,$$P'              `$$$.     Host: KVM/QEMU (Standard PC (i440FX + PIIX, 1996) pc-i440fx-5.2)
',$$P       ,ggs.     `$$b:   Kernel: 6.1.0-23-amd64
`d$$'     ,$P"'   .    $$$    Uptime: 38 mins
 $$P      d$'     ,    $$P    Packages: 1549 (dpkg)
 $$:      $$.   -    ,d$$'    Shell: bash 5.2.15
 $$;      Y$b._   _,d$P'      Resolution: 1024x768
 Y$$.    ."Y$$$$P"'         Terminal: /dev/pts/0
 `$$b      "-.__              CPU: Intel Xeon E5-2690 v2 (4) @ 2.999GHz
  `Y$$                        GPU: 00:02.0 Vendor 1234 Device 1111
   `Y$$.                      Memory: 3024MiB / 7940MiB
     `$$b.
       `Y$$b.
          `"Y$b._
              `"""
Asked by Ryan Lue (1176 rep)
Aug 23, 2024, 09:38 PM
Last activity: Aug 26, 2024, 06:38 PM