How do I disable password prompts when doing git push/pull?

36

15

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?

whirlwin

Posted 2011-09-22T07:59:27.763

Reputation: 637

5What is the protocol used by your repo address? ssh? https? – VonC – 2011-09-22T08:10:11.020

Answers

23

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 user@git.repo:id_rsa.tmp
$ ssh user@git.repo
$ 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/

Jin

Posted 2011-09-22T07:59:27.763

Reputation: 4 107

@slhck Ah, didn't think of that! It'll be good to know the OS whirlwin is using before posting further instructions, though. – Jin – 2011-09-22T08:17:05.837

Thanks for the pointer. I Have updated the question accordingly! – whirlwin – 2011-09-22T08:22:59.273

1When 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 – MultiformeIngegno – 2013-04-06T00:38:25.090

28

Run

git config credential.helper store

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

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

thunderbird

Posted 2011-09-22T07:59:27.763

Reputation: 381

4this 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. – Giang Nguyen – 2016-11-04T18:37:13.147

2Note that store credential helper stores the password on disk unencrypted. – 0xc0de – 2019-05-24T11:25:40.240

6

You can also just change your passphrase and replace it by an empty string :
ssh-keygen -p

wip

Posted 2011-09-22T07:59:27.763

Reputation: 5 155

3Thank you. This is the fix for people who have an SSH key setup but aren't sure why they still need to input a passphrase. – Cory Danielson – 2014-08-19T16:23:23.283

1

using an ssh-agent is the more secure alternative to this. https://superuser.com/questions/426749/ssh-agent-and-ssh-add

– Jay R. Wren – 2017-10-30T21:04:37.360

3isn't this very wrong? as there will be no more security – titus – 2013-07-26T09:48:52.537

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 git@github.com:sshare/GLE.git

rj45

Posted 2011-09-22T07:59:27.763

Reputation: 126