Notes »

Sharing ssh-agent

Debian 12 seems to start a ssh-agent with i3, but I can’t find a way to access to that agent (the environment variables aren’t exported, apparently).

To fix that, I add to my ~/.profile the following:

export SSH_AUTH_SOCK=~/.cache/ssh-agent.$HOSTNAME.sock
ssh-add -l 2>/dev/null >/dev/null
# ssh-add will return 2 if can't connect to the socket
if [ $? -ge 2 ]; then
  ssh-agent -a "$SSH_AUTH_SOCK" >/dev/null

By default, a random path is used, which makes impossible to reuse an existing agent. This sets a fixed socket path for the host instead.

Then I have this add-my-key script to add my key to the agent:



ssh-add -l | grep $KEY -q
if [ $? -eq 0 ]; then
    echo "Key already in the agent."
    exit 0

echo "Adding key to the agent."
exec ssh-add $KEY

It will need to be run –entering the password– once per session.

Finally –this is optional–, I removed the has-ssh-agent option from /etc/X11/Xsession.options. I won’t be using that agent, so I prefer if is not started –I haven’t experienced any issues so far–.

Last updated Nov 2, 2023