Skip to content

Instantly share code, notes, and snippets.

@vaimalaviya1233
Forked from teebow1e/ssh_setup.md
Created June 30, 2025 06:24
Show Gist options
  • Save vaimalaviya1233/c03e6072a27111880373a29402402e2a to your computer and use it in GitHub Desktop.
Save vaimalaviya1233/c03e6072a27111880373a29402402e2a to your computer and use it in GitHub Desktop.
Integrate SSH keys to GitHub for working with private repo (or personal access)

Get SSH key working

  1. Create a SSH key
ssh-keygen -t rsa -C "[email protected]"
# this is also okay
ssh-keygen -t rsa -b 4096 -C "[email protected]"
# maybe this (up to your preference)
ssh-keygen -t ed25519 -C "[email protected]"
  1. Copy the public key (.pub) to clipboard
  2. Paste into GitHub SSH and GPG keys page
  3. Verify the connectivity
ssh -T -v [email protected]
# or this if you use custom key name (instead of the normal id_rsa)
# more information: https://serverfault.com/questions/1119891/ssh-not-working-when-custom-key-name-is-used
ssh -T -v -i <custom_file_name> [email protected]
  1. By default, for some reason, new session of Bash/ZSH may not load your SSH key, therefore, you need to initialize a SSH agent and load your key each time you start a new session.
ssh-add &>/dev/null || eval `ssh-agent` &>/dev/null
[ $? -eq 0 ] && {
  ssh-add ~/.ssh/<your_key_name> &>/dev/null
}

Sidenote: If you are using SSH key and works with private stuff, you need to interact with them using SSH protocol, not HTTP.

Signing your Commits

  1. Upload your previously-created keys (or just create a new key) to GitHub SSH and GPG keys page. Make sure to specify it as Signing Key. 1.1. Optional
  • Run this command to always verify your commit in a specific local repo: git config commit.gpgsign true
  • Run this command to always verify your commit: git config --global commit.gpgsign true
  1. Let Git know about your signing key
git config --global gpg.format ssh
git config --global user.signingkey /PATH/TO/.SSH/KEY.PUB
  1. Verify by signing a commit
git commit -S -m "<example>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment