6

I tried to git pull from github origin and got this:

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

instead of promt for username and password. My ~/.ssh/ folder is empty, so I'm confused what publickey is meant here.

How does git decide whether to ask for username/password? How can I force him to do so? (I don't want for some reason to use ssh keys)

Vasily Mitch
  • 357
  • 2
  • 10

2 Answers2

16

This happens because you're using SSH url and probably your SSH settings are not configured (you're also saying your ~/.ssh directory is empty).

You can check the current remote url(s) using the following command:

git remote -v

If you want to use basic authentication (username + password), you have to use https.

Do this in your repository:

git remote set-url origin https://github.com/your-username/repository.git

Replace your-username with your GitHub username and repository with the repository name. Also, replace origin with your remote name (if you're using another remote name, probably you are not).

As @Abizern mentioned, you can configure the SSH keys and use the SSH urls instead. That may speed up your work not annoying you to enter the username/password every time.

There are other alternatives to prevent git from asking for your password every time. Here is one of them, by setting the cache time.

...or you can provide your password/token in the HTTPs url, as mentioned here.

git remote set-url origin https://username:password@github.com/username/repository.git
Salomon Zhang
  • 1,553
  • 3
  • 23
  • 41
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • You don't have to enter the username password everytime. Again, there is documentation on the site that tell you how to set up the osx-credetial-helper to save this in your keychain after the first time you use it. https://help.github.com/articles/caching-your-github-password-in-git/ – Abizern Oct 07 '15 at 11:28
  • @Abizern I already pointed that in my answer, exactly that url. :) – Ionică Bizău Oct 07 '15 at 11:29
  • I've been looking for a solution for this problem for 2 hours and setting the password/token in the HTTPs url is the only thing that worked (it wouldn't ask for my password when I tried to pull, even though I resetted the managers). Great answer. – Bogdan Nov 12 '21 at 12:23
3

Alternatively, set up an SSH key for Github.

It's quite simple - there is a full guide on the GitHub site.

This also has the advantage of allowing you to revoke the keys from the GitHub site without access to the computer. Useful if you are using a work computer.

Edited to add

I should note that GitHub recommends using https for access.

Abizern
  • 146,289
  • 39
  • 203
  • 257