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.

  1. Create a new folder: mkdir ~/.config/systemd/user
  2. Create a new ssh-agent service: vim ~/.config/systemd/user/ssh-agent.service
  3. Add the following to the service
Description=SSH key agent

ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK

  1. Enable the ssh-agent systemd service: systemctl --user enable ssh-agent
  2. Start the ssh-agent systemd service: systemctl --user start ssh-agent
  3. Add the following entry to your bash profile ~/.profile export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/openssh_agent"
  4. 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.

  1. Configure git to use SSH keys: git config --global gpg.format ssh
  2. Generate an SSH to interact with git (you can skip this step if you have one already) ssh-keygen -t ed25519
  3. Tell git to use the specific public key to sign your commits: git config --global user.signingkey $HOME/.ssh/
  4. Add your ssh keys to the agent: ssh-add
  5. Verify the key was added: ssh-add -l
  6. Tell git to sign all your commits by default: git config commit.gpgsign true (alternatively use git commit -S -m "YOUR_COMMIT_MESSAGE" to sign single commits)

Subscribe to Tech

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.