Skip to content

Git SSH setup

Simon Chapman edited this page Sep 5, 2024 · 5 revisions

Generation

To generate key(s) you can run ssh-keygen -t ed25519 -C "[email protected]". You will then need to add the contents of the public key (.pub) to your account's SSH Keys section on the relevent host (GitLab/GitHub).

Adding to agent

Mac / Linux

In your .bashrc, .zshrc or equivalent add the following lines:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

Repeat the ssh-add line for each private key you have, changing the filename as appropriate.

Windows

Git Bash

Copy the contents of this script snippet into your .bash_profile, .bashrc, .profile or equivalent, this will ensure all your keys get loaded into the agent (and only one agent executable ever runs).

Note that the script assumes that all the keys are placed in ~/.ssh and all their names end in _rsa. If not, you will need to modify the script accordingly to load the right filenames.

WSL

sudo apt install keychain # Or the equivalent for your distro of choice

And add the following lines to ~/.bashrc or ~/.zshrc:

keychain --nogui $HOME/.ssh/*_rsa
source $HOME/.keychain/$HOSTNAME-sh # Under ZSH, the variable is just $HOST
Clone this wiki locally