Question

When I do git pull via the command line, it always asks for my github username and password. I'd like to tell it to use the ssh key in github, and never have to worry about it again. How do you do this?

Was it helpful?

Solution

Assuming that you have used ssh-keygen to generate a key pair and uploaded the public key in the appropriate place in your github account, you should be able to set remote to use the url git@github.com:username/repo.git.

git remote set-url origin git@github.com:username/repo.git

If you do not have local changes that you care about, you can just delete your local repository and clone again:

git clone git@github.com:username/repo.git

Here are github's instructions on this setup, which you can use as a reference as needed.

OTHER TIPS

To tell Git to use the key that you generated, add the following to your ssh config (on Linux, usually located at ~/.ssh/config):

Host github.com
  User git
  IdentityFile ~/.ssh/id_rsa

For the IdentityFile you should use the key that was generated by ssh-keygen (not the one whose name ends in .pub). The User must always be git.

Another possibility is that after creating the ssh you may have moved the keys to a different folder. In that case, ssh-add ~/yourkeyfolder/yourkey

This will ensure that your key is known to the os.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top