Posted on February 3, 2022, 3:00 pm By agathezol
It is pretty simple to setup ssh-agent as a user service under systemd. On Manjaro/Arch, start by installing xdg-user-dirs if it isn’t already. Once installed, create the file /etc/xdg/systemd/user/ssh-agent.service with this contents:
[Unit] Description=SSH key agent [Service] Type=simple Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket # DISPLAY required for ssh-askpass to work Environment=DISPLAY=:0 ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK [Install] WantedBy=default.target
Then, in your shell (for sh based shells like bash and zsh) add:
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
Then just enable the user service with:
systemctl enable ssh-agent.service --user systemctl start ssh-agent.service --user
At this point, when you open a terminal and try to ssh somewhere if you need to unlock a key you will be prompted for your password inside the terminal. After that, you are unlocked up until you log out of your X11 session. Important to keep in mind if you step away from your desk as your keys are unlocked!
Categories: General, Linux