54

Every time I want to push and/or pull from the terminal (in Linux) I have to enter a password. How do I remove this so that it pulls and/or pushes without the password?

1
  • 6
    What is the protocol used by your repo address? ssh? https?
    – VonC
    Sep 22, 2011 at 8:10

4 Answers 4

29

Generate a private/public key pair for password-less authentication.

For Linux, your keys are stored in ~/.ssh.

If you already have files in ~/.ssh that's named id_rsa and id_rsa.pub, then you already have a key pair. Append the contents of your public key (that's id_rsa.pub) to the Git repository's ~/.ssh/authorized_keys file.

$ scp ~/.ssh/id_rsa.pub [email protected]:id_rsa.tmp
$ ssh [email protected]
$ cat id_rsa.tmp >> .ssh/authorized_keys

If you don't have the key pair, generate one with

$ ssh-keygen -t rsa

Read this for further instructions: http://inchoo.net/tools-frameworks/how-to-generate-ssh-keys-for-git-authorization/

2
  • 1
    When I run the first command I get a: You appear to be using ssh to clone a git:// URL. Make sure your core.gitProxy config option and the GIT_PROXY_COMMAND environment variable are NOT set. lost connection Apr 6, 2013 at 0:38
  • This only works for ssh. If op must use https, this process will not work.
    – Dave
    Oct 4, 2022 at 19:18
40

Run

git config credential.helper store 

This will store your credentials in a folder inside root. You need to run git pull/git push after this command and give the username and password for the first time. After this, it will not prompt for username and password. Details at https://git-scm.com/docs/git-credential-store

As 0xc0de wrote in a comment, this will store the password unencrypted!

4
  • 7
    this should be selected as the correct answer for this question. IMO, the OP wanted to ask about a solution for https to avoid having to enter username/password again and again, not switching to ssh solution. 1+ for this answer.
    – JNN
    Nov 4, 2016 at 18:37
  • 5
    Note that store credential helper stores the password on disk unencrypted.
    – 0xc0de
    May 24, 2019 at 11:25
  • Use git config --global credential.helper 'cache --timeout 7200', if you want your Linux to store the password only for a specific amount of time. Here, 7200 = 7200 seconds = 2 hours. Source: stackoverflow.com/a/28562679/10358768
    – Milan
    Aug 21, 2020 at 21:31
  • This doesn't work with git over ssh. In such a case, try Jin's solution. It worked for me.
    – Kai Carver
    Feb 20, 2023 at 13:47
1

I had created a new branch and after that when I pulling, I had to enter the user name and password. Then I resolve the problem re-cloning the branch with ssh address (which is on the relevant repository site).

For example:

git clone [email protected]:sshare/GLE.git
1

The default caching time is 900 seconds (or 15 minutes), after which Git will prompt you to enter your username and password again. You can change it as follows (1800 seconds = 30 minutes or 3600 seconds = 1hour). ($ represents the shell prompt as a normal non-elevated user)

$ git config --global credential.helper 'cache --timeout=18000'

OR

$ git config --global credential.helper 'cache --timeout=36000'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .