Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.