SSH Agent as Systemd User-Service
Create a systemd user-level config directory:
mdkir -p .config/systemd/user/
Create the service unit file:
.config/systemd/user/ssh-agent.service
[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
Enable the unit.
systemctl --user enable --now ssh-agent
Add this to .bashrc
so that the shell can find the socket:
SSH_AUTH_SOCK="${XDG_RUNTIME_DIR}/ssh-agent.socket"
Then, add a key to the agent:
ssh-add ~/.ssh/your-key.pem
From now until logout, keys will be stored in the agent.
Sensitive keys can be removed after use with ssh-add -D