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)
The most likely reason for this is that Git has been configured to use a credential helper. The configuration could have been made a) for all users in your system b) only for your user c) for a specific repository.
You can avoid being prompted for your password by configuring Git to cache your credentials for you. Once you've configured credential caching, Git automatically uses your cached personal access token when you pull or push a repository using HTTPS.
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. It's easier to set up than SSH, and usually works through strict firewalls and proxies.
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:[email protected]/username/repository.git
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With