I use xautolock
to lock the screen and suspend my laptop after a given amount of time of inactivity. This works fine. This is how xautolock
is started from .xsessionrc
:
xautolock -time 60 -detectsleep -locker '~/bin/lockscreen --suspend' &
The ~/bin/lockscreen
script does, among other things, ssh-add -D
to remove all SSH keys from the running SSH agent. This, however does not work when xautolock
is spawned from .xsessionrc
- the ssh-add -D
command complains that it cannot talk to the authentication agent.
However, I can ssh-add -D
from my terminal just fine, and if I pkill xautolock
and then run the xautolock
command from my .xsessionrc
in a terminal, everything works as expected.
Why can't the ssh-add -D
process spawned from xautolock
spawned from .xsessionrc
talk to the SSH agent, but ssh-add -D
spawned from xautolock
spawned from a regular terminal can?
ps auf
shows this tree:
root 24126 0.0 0.1 105812 5032 tty1 Ss 18:34 0:00 /bin/login --
andreas 24132 0.0 0.1 40232 4956 tty1 S 18:34 0:00 \_ -zsh
andreas 24140 0.0 0.0 4328 1576 tty1 S+ 18:34 0:00 \_ /bin/sh /usr/bin/startx
andreas 24162 0.0 0.0 15944 1952 tty1 S+ 18:34 0:00 \_ xinit /etc/X11/xinit/xinitrc -- /etc/X11/xinit/xserverrc :0 vt1 -auth /tmp/serverauth.afXu0ohTRz
root 24163 1.4 0.5 165868 20048 tty1 S 18:34 0:02 \_ /usr/bin/X -nolisten tcp :0 vt1 -auth /tmp/serverauth.afXu0ohTRz
andreas 24169 0.0 0.2 113572 10600 tty1 S 18:34 0:00 \_ x-window-manager
andreas 24203 0.0 0.7 489436 26380 tty1 Sl 18:34 0:00 \_ nm-applet
andreas 24204 0.0 0.0 20140 2700 tty1 S 18:34 0:00 \_ xautolock -time 60 -detectsleep -locker ~/bin/lockscreen --suspend
andreas 24209 0.0 0.0 22196 2680 tty1 S 18:34 0:00 \_ /usr/bin/unclutter -idle 1 -root
andreas 24212 0.0 0.0 10688 340 ? Ss 18:34 0:00 \_ /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session x-window-manager
My only working theory is that because xautolock
is started before the SSH agent, the forked ssh-add
command doesn't know about the agent's existence, but that seems very odd to me.