I\'ve been somewhat \'putting up\' with Github always asking for my username and password when I clone a repository. I want to bypass this step because it is an annoyance w
Same problem to me and the solution was:
See this github doc to convert remote's URL from https to ssh. To check if remote's URL is ssh or https, use git remote -v. To switch from https to ssh: git remote set-url origin git@github.com:USERNAME/REPOSITORY.git @jeeYem
If you work with HTTPs
urls, it'll always ask for your username / password.
If you're correctly using SSH
when cloning / setting remotes. Then make sure you have a ssh-agent to remember your password. That way, you'll only enter your passphrase once by terminal session.
If it is still too annoying, then simply set a ssh-key without passphrase.
You can remove passphrase for the key
$ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
or you can run
$ ssh-keygen -p
you get a prompt for keyfile. By default it ~/.ssh/id_rsa
so press enter
You'll be prompted for current pass phrase enter it.
Then there will be a prompt for new pass phrase, press enter
TL;DR
You need to use an ssh agent. So, open terminal & tryssh-add
before pushing to git. Enter your passphrase when prompted.
Check out the original StackExchange answer here
On Mac OSX you can add your private key to the keychain using the command:
ssh-add -K /path/to/private_key
If your private key is stored at ~/.ssh and is named id_rsa:
ssh-add -K ~/.ssh/id_rsa
You will then be prompted for your password, which will be stored in your keychain.
Edit - Handle restart
In order to not have to fill in your password even after a restart add the following to your ssh configuration file (commonly located at ~/.ssh/config)
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
This answer is primarily for windows users and also equally relevant if you're having trouble cloning with tfs, github or gitlab on any other OS.
The default authentication mode when using SSH is the private key. Whenever that fails for some reason, the ssh-agent falls back to username and password based authentication.
There are several reasons why the default key based authentication might have failed. Following are the most common cases :
a) The ssh-agent cannot find the default private key file which is id_rsa, and no other key path is specified explicitly.
b) The public key stored in the server is incorrect.
c) The path you're trying to clone is incorrect.
In any case, to troubleshoot the issue, first of all execute the git clone command with verbose logging with the command :
GIT_TRACE=1 GIT_SSH_COMMAND="ssh -vvv" git clone ssh://pathToYourRepo
You can go through each step in the log to get an intuition of what the issue might be.
Troubleshooting in case of (a)
Make sure you have the default key name id_rsa in the .ssh directory. You might have specified some different keyname when generating the key with ssh-keygen command or maybe there isn't any key at all).
In case you want to specify a different key for authentication, use the following command :
ssh-agent bash -c 'ssh-add ~/.ssh/anotherKey; git clone ssh://pathToYourRepo'
Troubleshooting in case of (b)
Troubleshooting in case of (c)