Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is github asking me username/password although I setup SSH authentication?

Tags:

git

github

ssh

I have followed these instructions to set up the SSH key for github. But now when I do

> git pull Username for 'https://github.com':  

in a repository on the local computer I have taken the public SSH key from, I am still asked for a username/password. Did I miss a step?

like image 992
Alex Avatar asked Sep 21 '17 07:09

Alex


People also ask

Why does GitHub keep asking for my password?

If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository. Using an HTTPS remote URL has some advantages compared with using SSH.

How do I stop Git push from asking for username and password?

Issue the command git fetch/push/pull. You will not then be prompted for the password.


2 Answers

You need to tell Git to use SSH protocol instead of HTTPS. On the repository page on GitHub, select Clone or Download and Use SSH. You will get a URL for the SSH protocol in the form [email protected]:<user>/<repo>.git.

Then run the following command in your working tree to tell Git to use this URL instead of the current one:

git remote set-url origin [email protected]:<user>/<repo>.git 

This is also explained in the GitHub Help.

The method above won’t cause the repository to be cloned again, it just changes the communication protocol used for future synchronization between your local repo and GitHub.

Alternatively, you could set up a new remote using git remote add <new-remote-name> <url> and then git pull <new-remote-name> but Git would keep track of both protocols as separate remotes, so I do not recommend this.

like image 52
Melebius Avatar answered Sep 24 '22 03:09

Melebius


This can also be done by editing the git config file for your project. With your favourite editor open .git/config and find the existing URL:

[remote "origin"]     url=https://github.com/<usr>/<repo>.git  

Change to:

[remote "origin"]     [email protected]:<usr>/<repo>.git  

Personally, I find this a bit easier to remember at the risk of being a little more 'internal'.

like image 44
meesern Avatar answered Sep 20 '22 03:09

meesern