SSH-Agent as systemd user service
- Posted: August 28, 2025
- Updated: August 28, 2025
Create ~/.config/systemd/user/ssh-agent.service with:
[Unit]
Description=OpenSSH Agent
Documentation=man:ssh-agent(1)
Requires=ssh-agent.socket
[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
Useful commands and tips
# To start the service:
systemctl --user start ssh-agent.service
# To reload systemd daemon:
systemctl --user daemon-reload
# To start this service automatically:
systemctl --user enable ssh-agent.service
Let chezmoi manage this folder:
chezmoi add ~/.config/systemd/user
You can also do the same thing for other user services, such as foot-server if you use foot as your terminal emulator. My other user services.