Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active September 17, 2024 05:27
Show Gist options
  • Save magnetikonline/b6255da90606fe9c5c25d3333c98c90d to your computer and use it in GitHub Desktop.
Save magnetikonline/b6255da90606fe9c5c25d3333c98c90d to your computer and use it in GitHub Desktop.
Add user ssh-agent as daemon to Ubuntu 18.04LTS server.

Add user ssh-agent as daemon to Ubuntu 18.04LTS server

Create a new systemd user unit, which starts ssh-agent upon login to server. Will remain resident until the final session for the user has logged out.

Steps

  • Create /etc/systemd/user/ssh-agent.service.

  • Run the following commands (under your user account, not root) to install the systemd unit and start:

     $ systemctl --user enable ssh-agent.service
     $ systemctl --user start ssh-agent.service
  • Add the following to ~/.bashrc:

     export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
  • Logout then login, confirm ssh-agent is running:

     $ systemctl --user status ssh-agent.service
     $ ssh-add -L
  • Done.

Reference

[Unit]
Description=SSH authentication agent
[Service]
ExecStart=/usr/bin/ssh-agent -a %t/ssh-agent.socket -D
Type=simple
[Install]
WantedBy=default.target
@rumbarum
Copy link

Thank you for tip.
Your file do not works for me. (ubuntu20.22)
I fixed it like below,

[Unit]
Description=SSH key agent

[Service]
Type=simple
Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK

[Install]
WantedBy=default.target

and works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment