Hi,
@bedna it worked with the systemd service. Thanks for the hint.I document here again the steps I have done so that other users can easily follow this.
Set up SSH agent based on systemd for a special user
Create the service file under ~/.config/systemd/user/ssh-agent.service.
[Unit]
Description=SSH key agent (User service)
[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
Add the following line to the ~/.bash_profile of the respective user to be able to access the socket.
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
Add the following line to the user’s SSH config file under $HOME/.ssh/config.
AddKeysToAgent yes
Now activate and start the user service.
$ systemctl --user enable --now ssh-agent
The status of the newly created ssh-agent service is queried in this way.
$ systemctl --user status ssh-agent
● ssh-agent.service - SSH key agent (User service)
Loaded: loaded (/home/michael/.config/systemd/user/ssh-agent.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2024-03-11 14:24:54 CET; 4h 18min ago
Main PID: 2478 (ssh-agent)
Tasks: 1 (limit: 18903)
Memory: 1.5M
CPU: 27ms
CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/ssh-agent.service
└─2478 /usr/bin/ssh-agent -D -a /run/user/1000/ssh-agent.socket
Mär 11 14:24:54 neonlight systemd[2469]: Started SSH key agent (User service).
Mär 11 14:24:54 neonlight ssh-agent[2478]: SSH_AUTH_SOCK=/run/user/1000/ssh-agent.socket; export SSH_AUTH_SOCK;
Mär 11 14:24:54 neonlight ssh-agent[2478]: echo Agent pid 2478;
Info from: