Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git always asks for my ssh-key passphrase

Tags:

git

github

I have a problem that occurs when using git.

When I use the command git pull origin my_branch or git fetch or git push origin my_branch, git always asks for my passphrase for key. I don't understand why this occurs?

Can someone please explain why and how to avoid entering the passphrase each time.

$ git fetch
Enter passphrase for key '/home/khanhpn/.ssh/id_rsa':
like image 652
Khanh Pham Avatar asked Jul 13 '15 07:07

Khanh Pham


People also ask

How do I get Git to stop asking for passphrase?

You can avoid being prompted for your password by configuring Git to cache your credentials for you. Once you've configured credential caching, Git automatically uses your cached personal access token when you pull or push a repository using HTTPS.

Why does SSH keep asking for passphrase?

There may be times in which you don't want the passphrase stored in the keychain, but don't want to have to enter the passphrase over and over again. This will ask you for the passphrase, enter it and it will not ask again until you restart.

How do I stop SSH from prompting key passphrase?

Use ssh-add to add the keys to the list maintained by ssh-agent. After you add a private key password to ssh-agent, you do not need to enter it each time you connect to a remote host with your public key.

How do I fix Git always asking for credentials?

Entering Git Username and Password in Remote URL To prevent Git from asking for your username and password, you can enter the login credentials in the URL as shown. The main drawback of this method that your username and password will be saved in the command in the Shell history file.


2 Answers

Like Nasreddine says, it's because your key is encrypted with a passphrase to prevent others from reading it.

The most convenient way of using passphrased keys is by using ssh-agent to start an authentication agent (which runs in the background):

$ eval "$(ssh-agent)"
Agent pid 44304

...and then using ssh-add to register your key with the agent so that it's used automatically for subsequent SSH connections:

$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/khanhpn/.ssh/id_rsa:

You'll be asked to enter your passphrase when you run ssh-add, but you won't need to do so again while ssh-agent is running.

You can find more information on GitHub. Also note that you'll have to do this every time you log in, so you might like to add the eval "$(ssh-agent)" step to your .profile script.

like image 102
Will Vousden Avatar answered Oct 22 '22 23:10

Will Vousden


It's because your private SSH key is protected using a passphrase. You can remove it using this command (not recommended since anyone could copy your key and use it to access your repos/account):

$ ssh-keygen -p
Enter file in which the key is (/path/to/your/.ssh/key):

enter your current passphrase when prompted here:

Enter old passphrase:
Key has comment 'rsa w/o comment'

leave empty if you want to remove the passphrase when prompted here:

Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.
like image 11
Nasreddine Avatar answered Oct 22 '22 23:10

Nasreddine