How To Stop Git From Asking For A Password?

Dnbhatt
GopenSource

--

Whenever you push something to the remote repo or pull something from the remote repo, bash asks you to enter the username and password to complete the command execution. Isn’t it too boring? If so, how can you get rid of it?

One of the ways to avoid it is to create “SSH Key-Pair” in your GitHub account. Following are the steps to be followed to stop git from asking for username and password:

Generate SSH-Key

Firstly, check whether you have any existing SSH-Key linked with your GitHub account or not. Enter the following command line to know this.

$ ls -al ~/.ssh

If the output of the command shows any file such as id_rsa, id_rsa.pub, or id_ed25519.pub that means you already have an SSH-Key build and linked with your account. These are the filename of the public key. If so, go directly to the next section. If the output doesn’t show any such file(s), generate a new SSH-key with the following commands:

$ ssh-keygen -t rsa -C “Your_email@gmail.com”

As soon as you click the enter, bash will ask you to set the file location. A file is created in your local machine, with type SSH, in which your private SSH-Key will be written. You can set the file location or simply press enter to proceed with the default file location. After this, bash will ask you to set the passphrase(password). Enter the password and your SSH-Key is generate.

Add your SSH-key to the ssh-agent

You can start running ssh-agent with the following command:

$ exec ssh-agent bash

$ eval “$(ssh-agent -s)” or $ eval ‘ssh-agent -s’

Enter the below-given command to add the Key to ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.

$ ssh-add ~/.ssh/id_rsa

Add the SSH Key to your GitHub account

At First, we have to copy the SSH-Key to the clipboard with the following command:

$ clip < ~/.ssh/id_rsa.pub

Now, open your GitHub Account. => In the upper-right corner of any page, click your profile photo, then click Settings. => In the user settings sidebar, click SSH and GPG keys. => Click New SSH key or Add SSH key. => In the “Title” field, add a descriptive label for the new key. => Paste your key into the “Key” field. => Click Add SSH key. => If prompted, confirm your GitHub password. This will add a new SSH-Key to your GitHub account.

Finally, run the below-given command to fulfill our purpose:

$ git config --global credential.helper wincred

--

--