59

I'm using git bash and I setup ssh key using ssh-keygen and each time I do something with a repo git ask me for passphrase for /c/Users/jankiewj/.ssh/id_rsa. Is there a way to disable that passphrase.

78

You can run this in git bash:

eval `ssh-agent -s`
ssh-add ~/.ssh/*_rsa

it will ask for pass phrase in the second command, and that's it. Each additional action you will need to do (which once required pass phrase) won't ask you for the pass phrase (see an example in the screen shot below):

adding pass phrase in git bash on Windows

| improve this answer | |
  • 11
    I have to enter it again, as soon as I close git bash... is there a permanent solution? – Black Sep 18 '18 at 7:59
  • 2
    @Black it's per bash session, I've put this in .bashrc so each time I open git bash I get the prompt and for that session I'm all set. – jcubic Sep 18 '18 at 9:36
  • What exactly do you put in .bashrc? And where is .bashrc? – Black Sep 18 '18 at 9:38
  • Edit: nevermind, You have to create the file yourselv in ~/.bashrc then enter the lines from your post into it and save, thats it :) thx! – Black Sep 18 '18 at 9:55
  • Instead of using the lines above, especially in the .bashrc, I would use a script, and place it in either the .bash_profile or .profile. Here is a snippet of the main portion of my .bash_profile, it should resolve this for anyone still looking for an answer; it's similar to an answer below. At the top of the script I load up my .bashrc, which if not applicable just leave that out. Note: you will need to change references to id_rsa to whatever you named your private SSH key, and maybe the path. – Rockin4Life33 Aug 6 '19 at 1:41
16

A slightly better and permanent solution is to auto launch the ssh-agent when opening the git bash on windows. You can copy/paste the below in your .profile or .bashrc. I prefer to put it on the .profile

env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }

agent_load_env

# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi

unset env

This solution was taken from this github help article

| improve this answer | |
  • I've put my simple code into .bashrc, how your solution different? On Windows bash each shell is independent so agent is never running when you run the shell. – jcubic Apr 5 '19 at 7:41
  • Solution works fine by putting the code into the .bashrc. Prompting the ssh passphrase only at the first time. Safed my life. Thank you. – Ben Asmussen Jun 10 '19 at 19:39
  • thanks that's very saving my life. – gumuruh Jul 13 '19 at 14:38
  • This should really be the accepted answer as it presents a solution that is persistent and better meets what I think the OP was asking. – Richard D Jul 17 '19 at 17:00
  • What do I do if I accidentally typed the wrong password on startup? Edit: Based on superuser.com/a/271673/647110, you can ssh-add -D to delete all keys. – Nils Guillermin Aug 19 '19 at 15:16
2

Im not sure if I want to recommend it, but when you create the Key and asked to set password, just hit enter and skip the password.

Have a look at this link for how to use ssh-keygen: https://help.github.com/articles/working-with-ssh-key-passphrases/

Perhaps ssh-agent can help you somehow. But not sure without knowing your current system.

| improve this answer | |
  • 7
    definitely not a good answer – Kennet Celeste Sep 9 '19 at 2:40
  • It was the only way to solve it on windows 10. After following all the steps of "Generating a new SSH key and adding it to the ssh-agent" github guide, it was always asking me for the passphrase. Even after added it. That behavior was breaking my maven deployment flow because at mvn release:perform phase it tries to checkout the release tag without providing the passphrase. So only clearing the passphrase solved this issue. – Fernando Miguel Carvalho Dec 17 '19 at 12:47
-4

Enter this git command in your repos location "ssh-keygen -p" This will then prompt you to enter the keyfile location, the old passphrase, and the new passphrase (which can be left blank to have no passphrase). Don't enter anything in new password and it will remove passphrase

| improve this answer | |
  • 2
    Leaving a blank password is insecure and many corporate devs won't be able to have a blank passphrase due to restriction. It's a lame workaround, not a solution for OP issue. – cbaldan Jun 2 '19 at 16:06
  • lame perhaps, but for local use only, Tasty and expeditious™ – Jim P Sep 17 '19 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.