Linux: setup ssh-agent
Currently I am using Debian Bookworm and I need to setup the ssh-agent
to be able to sign Github commits, so here it's how I did it.
- Create a new folder:
mkdir ~/.config/systemd/user
- Create a new ssh-agent service:
vim ~/.config/systemd/user/ssh-agent.service
- Add the following to the 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 ssh-agent systemd service:
systemctl --user enable ssh-agent
- Start the ssh-agent systemd service:
systemctl --user start ssh-agent
- Add the following entry to your bash profile
~/.profile
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/openssh_agent"
- Activate it:
source ~/.profile
Once the above is done you'll have your user specific ssh-agent started at boot.
The next step is to tell git
to sign your commits.
- Configure
git
to use SSH keys:git config --global gpg.format ssh
- Generate an SSH to interact with git (you can skip this step if you have one already)
ssh-keygen -t ed25519
- Tell git to use the specific public key to sign your commits:
git config --global user.signingkey $HOME/.ssh/id_ed25519.pub
- Add your ssh keys to the agent:
ssh-add
- Verify the key was added:
ssh-add -l
- Tell git to sign all your commits by default:
git config commit.gpgsign true
(alternatively usegit commit -S -m "YOUR_COMMIT_MESSAGE"
to sign single commits)