Skip to content

Instantly share code, notes, and snippets.

@fabriciorsf
Forked from magnetikonline/README.md
Last active May 3, 2020 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabriciorsf/c41217780ee05a5098b1de79f49f2a2a to your computer and use it in GitHub Desktop.
Save fabriciorsf/c41217780ee05a5098b1de79f49f2a2a to your computer and use it in GitHub Desktop.
Add user ssh-agent as daemon to Ubuntu 18.04LTS server.
[Unit]
Description=SSH authentication agent
[Service]
ExecStart=/usr/bin/ssh-agent -a %t/ssh-agent.socket -D
Type=simple
[Install]
WantedBy=default.target

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

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