Skip to content

Instantly share code, notes, and snippets.

@kyrose
Created September 14, 2019 19:53
Show Gist options
  • Save kyrose/5766bb67af905a2ec413b7974b499544 to your computer and use it in GitHub Desktop.
Save kyrose/5766bb67af905a2ec413b7974b499544 to your computer and use it in GitHub Desktop.
Tell Git which SSH key to use for commits
## In ~/.ssh/config add:
host github.com
HostName github.com
IdentityFile ~/.ssh/<keyname>
User git
## Create a new SSH key pair in the terminal
$ ssh-keygen -t rsa -b 4096 -C "dev@kyannerose.me"
> Generating public/private rsa key pair.
> Enter file in which to save the key (/home/j3nfain/.ssh/id_rsa): <keyname>
> Enter passphrase (empty for no passphrase):
> Enter same passphrase again:
## Start SSH agent in background
$ eval "$(ssh-agent -s)"
> Agent pid 59566
## Add new key to SSH agent
$ ssh-add ~/.ssh/<keyname>
## Set permissions for SSH files used with GitHub
# SSH rejects keys that are too easily read
chmod 400 ~/.ssh/<keyname>
### See next file
## Configure git's core.sshCommand globally
$ git config --global core.sshCommand "ssh -i ~/.ssh/<keyname> -F /dev/null"
## Configure git core.sshCommand per repo
$ cd repo
/repo$ git config core.sshCommand "ssh -i ~/.ssh/<keyname> -F /dev/null"
/repo$ git pull
/repo$ git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment