Git Enter Long Passphrase for Every Push

Git enter long passphrase for every push

You can use ssh-agent to remember your passphrase (Gnome automatically runs this for you, normally...).

$ ssh-agent bash
$ ssh-add
Enter passphrase for /home/elyobo/.ssh/id_rsa:
Identity added: /home/elyobo/.ssh/id_rsa (/home/elyobo/.ssh/id_rsa)

From now on, from within the terminal that you run this, your pass phrase will be remembered.

Ideally you'd get it working automatically, so all shells running within gnome would work; check out Gnome Keyring.

Git keeps asking me for my ssh key passphrase

Once you have started the SSH agent with:

eval $(ssh-agent)

Do either:

  1. To add your private key to it:

     ssh-add

    This will ask you your passphrase just once, and then you should be allowed to push, provided that you uploaded the public key to Github.

  2. To add and save your key permanently on macOS:

     ssh-add -K  

    This will persist it after you close and re-open it by storing it in user's keychain.

    If you see a warning about deprecated flags, try the new variant:

     ssh-add --apple-use-keychain 
  3. To add and save your key permanently on Ubuntu (or equivalent):

      ssh-add ~/.ssh/id_rsa

SSH Key - Still asking for password and passphrase

If you work with HTTPs urls, it'll always ask for your username / password. This could be solved using @Manavalan Gajapathy's comment (copying here):

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

If you're correctly using SSH when cloning / setting remotes: make sure you have a ssh-agent to remember your password (see this answer by @Komu). 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.

Git asks for username every time I push

Edit (by @dk14 as suggested by moderators and comments)

WARNING: If you use credential.helper store from the answer, your password is going to be stored completely unencrypted ("as is") at ~/.git-credentials. Please consult the comments section below or the answers from the "Linked" section, especially if your employer has zero tolerance for security issues.

Even though accepted, it doesn't answer the actual OP's question about omitting a username only (not password). For the readers with that exact problem @grawity's answer might come in handy.


Original answer (by @Alexander Zhu):

You can store your credentials using the following command

$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>

Also I suggest you to read

$ git help credentials

Why git can't remember my passphrase under Windows

I realize that this question is coming up on two years old, but I had the same issue and several answers here did not completely answer the question for me. Here are three step-by-step solutions, depending on whether you use TortoiseGit in addition to msysgit or not.

First solution Assumes Windows, msysgit, and PuTTY.

  1. Install msysgit and PuTTY as instructed.

  2. (Optional) Add PuTTY to your path. (If you do not do this, then any references to PuTTY commands below must be prefixed with the full path to the appropriate executable.)

  3. If you have not done so already, then generate a key hash as instructed at GitHub or as instructed by your Git host.

  4. Again, if you have not already done so, convert your key for use with PuTTY's pageant.exe using puttygen.exe. Instructions are in PuTTY's documentation, in this helpful guide, and several other places in cyberspace.

  5. Run PuTTY's pageant.exe, open your .ppk file ("Add Key"), and provide your passphrase for your key.

  6. Access Windows' environment variables dialog (Right-click on "Computer", Click on "Properties", Click on "Advanced system settings" or the "Advanced" tab, click on "Environment Variables"). Add the following environment variable:

    GIT_SSH=C:\full\path\to\plink.exe

    Replace "C:\full\path\to" with the full installation path to PuTTY, where plink.exe is found. It is probably best to add it to the "User variables" section. Also, make sure that the path you use to plink.exe matches the path you use for Pageant (pageant.exe). In some cases, you may have several installations of PuTTY because it might be installed along with other applications. Using plink.exe from one installation and pageant.exe from another will likely cause you trouble.

  7. Open a command prompt.

  8. If you are trying to connect to a git repository hosted at Github.com then run the following command:

    plink.exe git@github.com

    If the git repository you are trying to connect to is hosted somewhere else, then replace git@github.com with an appropriate user name and URL. (Assuming Github) You should be informed that the server's host key is not cached, and asked if you trust it. Answer with a y. This will add the server's host key to PuTTY's list of known hosts. Without this step, git commands will not work properly. After hitting enter, Github informs you that Github does not provide shell access. That's fine...we don't need it. (If you are connecting to some other host, and it gives you shell access, it is probably best to terminate the link without doing anything else.)

  9. All done! Git commands should now work from the command line. You may want to have pageant.exe load your .ppk file automatically at boot time, depending on how often you'll be needing it.

Second solution Assumes Windows, msysgit, and TortoiseGit.

TortoiseGit comes with PuTTY executables and a specially modified version of plink (called TortoisePlink.exe) that will make things easier.

  1. Install msysgit and TortoiseGit as instructed.

  2. If you have not done so already, then generate a key hash as instructed at GitHub or as instructed by your Git host.

  3. Again, if you have not already done so, convert your key for use with TortoiseGit's pageant.exe using TortoiseGit's puttygen.exe. Instructions are in PuTTY's documentation, in the helpful guide linked to in the first solution, and in several other places in cyberspace.

  4. Run TortoiseGit's pageant.exe, open your .ppk file ("Add Key") and provide your passphrase for your key.

  5. Access Windows' environment variables dialog (Right-click on "Computer", Click on "Properties", Click on "Advanced system settings" or the "Advanced" tab, click on "Environment Variables"). Add the following environment variable:

    GIT_SSH=C:\full\path\to\TortoisePlink.exe

    Replace "C:\full\path\to" with the full installation path to TortoiseGit, where TortoisePlink.exe is found. It is probably best to add it to the "User variables" section. Also, make sure that the path you use to TortoisePlink.exe matches the path you use for Pageant (pageant.exe). In some cases, you may have several installations of PuTTY because it might be installed along with other applications. Using TortoisePlink.exe from the TortoiseGit installation and pageant.exe from another installation of a different application (or from a standalone PuTTY installation) will likely cause you trouble.

  6. All done! Git commands should now work from the command line. The first time you try to connect to your git repository you will probably be informed that the server's host key is not cached, and asks if you trust the server. Click on "Yes". (This is TortoisePlink.exe in action.)

    You may want to have pageant.exe load your .ppk file automatically at boot time, depending on how often you'll be needing it.

Third solution Assumes Windows, msysgit, and the native command prompt.

  1. Install msysgit
  2. Make sure to allow git to be used on the MS-DOS command prompt
  3. Run start-ssh-agent
  4. Enter SSH passphrases
  5. All done! Git commands should now work in the native command prompt.

SSH asking every single time for passphrase

Ensure you are actually using SSH

This really sounds like your remote is not using SSH at all, but is using HTTP. In that case, every time you use the remote, it will ask you to authenticate.

You can check this by looking at your remote URLs. For SSH you want it to look like this:

$ git remote -v
origin git@github.com:yourUsername/yourRepo (fetch)
origin git@github.com:yourUsername/yourRepo (push)

If you are using HTTP, then it will instead look like this:

$ git remote -v
origin https://github.com/yourUsername/yourRepo.git (fetch)
origin https://github.com/yourUsername/yourRepo.git (push)

If you find it is set to use HTTP, it's easy to change.

git remote set-url origin git@github.com:yourUsername/yourRepo

SSH key asking for passphrase every time it is used

If it turns out that you are already using SSH, you should check your SSH configuration. There are two locations to check on a Mac.

  • /etc/ssh/ssh_config
  • /Users/{your_username}/.ssh/config

In particular, you do not want this setting:

AddKeysToAgent confirm

From the ssh_config man page:

AddKeysToAgent
Specifies whether keys should be automatically added to a running
ssh-agent(1). If this option is set to ``yes'' and a key is
loaded from a file, the key and its passphrase are added to the
agent with the default lifetime, as if by ssh-add(1). If this
option is set to ``ask'', ssh will require confirmation using the
SSH_ASKPASS program before adding a key (see ssh-add(1) for
details). If this option is set to ``confirm'', each use of the
key must be confirmed, as if the -c option was specified to
ssh-add(1). If this option is set to ``no'', no keys are added
to the agent. The argument must be ``yes'', ``confirm'',
``ask'', or ``no''. The default is ``no''.

And this is a description of the -c flag to ssh-add:

-c      Indicates that added identities should be subject to confirmation
before being used for authentication. Confirmation is performed
by ssh-askpass(1). Successful confirmation is signaled by a zero
exit status from ssh-askpass(1), rather than text entered into
the requester.

SSH key not present in agent at startup

After you restart the machine, the key being gone is normal. You have to add it at least once after the machine starts up.

Git push requires username and password

A common cause is cloning using the default (HTTPS) instead of SSH. You can correct this by going to your repository, clicking "Clone or download", then clicking the "Use SSH" button above the URL field and updating the URL of your origin remote like this:

git remote set-url origin git@github.com:username/repo.git

You can check if you have added the remote as HTTPS or SSH using:

git remote -v

This is documented at GitHub: Switching remote URLs from HTTPS to SSH.



Related Topics



Leave a reply



Submit