github linkedin
ssh-agent via systemd
Main issue if you’re not using desktop environment, how and when to start “ssh-agent” to store your ssh identity info. In case of full DE you have special daemon, like “gnome-keyring”.

On the other hand there are a lot of custom hacks like “how to use ssh-agent with screen” or “using with xinitrc”, etc.

Finally i’ve found that using ssh-agent with systemd is pretty useful. Example from arch wiki is not working for me (i assume for others also). I’m not using separate systemd socket and use additional SuccessExitStatus=2 parameter.

1) Create “~/.config/systemd/user/ssh-agent.service”

mkdir -p ~/.config/systemd/user
cat << EOF > ~/.config/systemd/user/ssh-agent.service
[Unit]
Description=ssh-agent

[Service]
ExecStart=/usr/bin/ssh-agent -d -a %t/ssh_auth_sock
SuccessExitStatus=2

[Install]
WantedBy=default.target
EOF

2) Start and enable ssh-agent service

systemctl –user daemon-reload
systemctl –user enable ssh-agent
systemctl –user start ssh-agent

3) Check that it works properly

ssh-add -l