Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I avoid the specification of the username and password at every git push?

I git push my work to a remote Git repository.

Every push will prompt me to input username and password. I would like to avoid it for every push, but how to configure to avoid it?

like image 920
Leem.fin Avatar asked Dec 21 '11 11:12

Leem.fin


People also ask

How do I stop Git push from asking for username and password?

Issue the command git fetch/push/pull. You will not then be prompted for the password.

Why does Git asking for my username and password every time?

If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository.

How do I make Git not ask for credentials?

Make Git store the username and password and it will never ask for them.


2 Answers

1. Generate an SSH key

Linux/Mac

Open terminal to create ssh keys:

cd ~                 #Your home directory ssh-keygen -t rsa    #Press enter for all values 

For Windows

(Only works if the commit program is capable of using certificates/private & public ssh keys)

  1. Use Putty Gen to generate a key
  2. Export the key as an open SSH key

Here is a walkthrough on putty gen for the above steps

2. Associate the SSH key with the remote repository

This step varies, depending on how your remote is set up.

  • If it is a GitHub repository and you have administrative privileges, go to settings and click 'add SSH key'. Copy the contents of your ~/.ssh/id_rsa.pub into the field labeled 'Key'.

  • If your repository is administered by somebody else, give the administrator your id_rsa.pub.

  • If your remote repository is administered by your, you can use this command for example:

    scp ~/.ssh/id_rsa.pub YOUR_USER@YOUR_IP:~/.ssh/authorized_keys/id_rsa.pub

3. Set your remote URL to a form that supports SSH 1

If you have done the steps above and are still getting the password prompt, make sure your repo URL is in the form

git+ssh://[email protected]/username/reponame.git 

as opposed to

https://github.com/username/reponame.git 

To see your repo URL, run:

git remote show origin 

You can change the URL with:

git remote set-url origin git+ssh://[email protected]/username/reponame.git 

[1] This section incorporates the answer from Eric P

like image 143
First Zero Avatar answered Oct 04 '22 06:10

First Zero


Permanently authenticating with Git repositories,

Run the following command to enable credential caching.

$ git config credential.helper store $ git push https://github.com/repo.git  Username for 'https://github.com': <USERNAME> Password for 'https://[email protected]': <PASSWORD> 

Use should also specify caching expire,

git config --global credential.helper 'cache --timeout 7200' 

After enabling credential caching, it will be cached for 7200 seconds (2 hours).

Note: Credential helper stores an unencrypted password on a local disk.

like image 23
Jaykumar Patel Avatar answered Oct 04 '22 07:10

Jaykumar Patel