I cloned a git repository from my Github account to my PC.
I want to work with both my PC and laptop, but with one Github account.
When I try to push to or pull from Github using my PC, it requires username and password, but not when using the laptop!
I don't want to type my username and password every time I interact with origin. What I am missing here?
You need to perform 2 steps -
Notice the git url is a
ssh
url and not an https url .. Which u can select from here.If you are using git (ex. git bash) under Windows (and if you don't want to switch from https to ssh)
you could also use https://github.com/Microsoft/Git-Credential-Manager-for-Windows
This application will keep username and password for you...
If you're using ssh and your private key is encrypted with a passphrase, then you'll still be prompted to enter the passphrase/password for the private key when you do network operations with Git like
push
,pull
, andfetch
.Use ssh-agent to save private key passphrase/password credentials
If you want to avoid having to enter your passphrase every time, you can use
ssh-agent
to store your private key passphrase credentials once per terminal session, as I explain in my answer to Could not open a connection to your authentication agent:In a Windows msysgit Bash, you need to evaluate the output of
ssh-agent
, but I'm not sure if you need to do the same in other development environments and operating systems.ssh-add
looks for a private key in your home.ssh
folder calledid_rsa
, which is the default name, but you can pass a filepath to a key with a different name.Killing the agent
When you're done with your terminal session, you can shutdown
ssh-agent
with the kill flag-k
:As explained in the
ssh-agent
manual:Optional timeout
Also, it can take an optional timeout parameter like so:
where
<timeout>
is of the format<n>h
for<n>
hours,<n>m
for<n>
minutes, and so on.According to the
ssh-agent
manual:See this page for more time formats.
Security warning for Cygwin users
Cygwin users should be aware of a potential security risk with using ssh-agent in Cygwin:
And at the cited link:
You basically have two options.
If you use the same user on both machines you need to copy the .pub key to your PC, so github knows that you are the same user.
If you have created a new .pub file for your PC and want to treat the machines as different users, you need to register the new .pub file on the github website.
If this still doesn't work it might be because ssh is not configured correctly and that ssh fail to find the location of your keys. Try
To get more information why SSH fails.
For windows git users, After running
git config --global credential.helper store
, if it still prompts for password, you'd better check where the config is written to. using this commandgit config --list --show-origin
In my case, manually edit config file 'C:\Program Files\Git\mingw64\etc\gitconfig', adding the following text , it works.
[credential] helper = store
Permanently authenticating with Git repositories,
Run following command to enable credential caching:
Use should also specify caching expire,
After enabling credential caching, it will be cached for 7200 seconds (2 hour).