Created
September 14, 2019 19:53
-
-
Save kyrose/5766bb67af905a2ec413b7974b499544 to your computer and use it in GitHub Desktop.
Tell Git which SSH key to use for commits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## In ~/.ssh/config add: | |
host github.com | |
HostName github.com | |
IdentityFile ~/.ssh/<keyname> | |
User git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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