How-to configure git to use ssh keys on windows
- Update git to the last version
- Create a key for your github account
ssh-keygen -t rsa -C "your-email-address"
That command will print
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/your_username/.ssh/id_rsa):
Enter the full path you want to save your key in and be sure the folder exists or you’ll get an error. For example:
c:/Users/villagra/.ssh/id_rsa_villagra
This will generate two files: id_rsa_villagra and id_rsa_villagra.pub
- Add the pub’s file contents in your github account => settings => ssh and gpg keys.
- Navigate to the repository you want to connect via ssh ahd type
git config core.sshCommand "ssh -i c:/Users/villagra/.ssh/id_rsa_villagra"
git config user.name "myusername"
git config user.email "myemail@email.com"
- Open the file .git/config of your repository and change the url for the remote “origin” from https://github.com/ to git@github.com:
It should looks like this one
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
sshCommand = ssh -i c:/Users/villagra/.ssh/id_rsa_villagra
[remote "origin"]
url = git@github.com:villagra/demo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
name = myusername
email = myemail@email.com
And done! Your repository now uses keys instead of credentials authentication.