Using GitBash on Windows--how to avoid entering passphrase for every Git command?

4,689 views
Skip to first unread message

gmazza

unread,
Feb 17, 2011, 11:23:05 AM2/17/11
to msysGit
Hi, subject line says it all, every git command I enter within Git
Bash requires me to keep typing in my ssh key passphrase. Is there a
way I can enter the passphrase just once for a session and have it
hold for all my git commands?

Thanks,
Glen

Erik Faye-Lund

unread,
Feb 17, 2011, 11:39:36 AM2/17/11
to gmazza, msysGit
On Thu, Feb 17, 2011 at 5:23 PM, gmazza <glen....@gmail.com> wrote:
> Hi, subject line says it all, every git command I enter within Git
> Bash requires me to keep typing in my ssh key passphrase.

By "every git command" you mean "every git command that uses SSH
transport", right?

> Is there a
> way I can enter the passphrase just once for a session and have it
> hold for all my git commands?
>

Yes, you need to install your ssh public key on the server. This is
usually a matter of running "ssh-keygen" and appending the content of
~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys file on the remote
machine. That way, you won't need to enter a password at all.

Johan Herland

unread,
Feb 17, 2011, 11:47:47 AM2/17/11
to gmazza, msy...@googlegroups.com

gmazza

unread,
Feb 17, 2011, 11:49:14 AM2/17/11
to msysGit
On Feb 17, 11:39 am, Erik Faye-Lund <kusmab...@gmail.com> wrote:
> On Thu, Feb 17, 2011 at 5:23 PM, gmazza <glen.ma...@gmail.com> wrote:
> > Hi, subject line says it all, every git command I enter within Git
> > Bash requires me to keep typing in my ssh key passphrase.
>
> By "every git command" you mean "every git command that uses SSH
> transport", right?
>

Yes. 10 git pulls require entering my passphrase 10 times, instead of
ideally just once.

> > Is there a
> > way I can enter the passphrase just once for a session and have it
> > hold for all my git commands?
>
> Yes, you need to install your ssh public key on the server. This is
> usually a matter of running "ssh-keygen" and appending the content of
> ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys file on the remote
> machine. That way, you won't need to enter a password at all.

I believe I've already done that--I use GitHub and this problem never
occurs when I'm using Linux (just need to enter my passphrase once and
that's good as long as I have the console window open. It's just
Windows and the GitBash shell that is having this problem, I'm not
sure why.

The passphrase is probably being used to sign my requests, so even
with the public key on the server the GitHub client is still going to
need to know that passphrase to do the signing.

Thanks,
Glen

Glen Mazza

unread,
Feb 17, 2011, 11:55:06 AM2/17/11
to Johan Herland, msy...@googlegroups.com
Actually, I *did* go to that very page prior to asking my question--note
that it is only valid for Linux and Mac OS. I'm using, again, Windows.
So your lmgtfy was a miss. :)

Glen

Johannes Schindelin

unread,
Feb 17, 2011, 11:58:11 AM2/17/11
to gmazza, msysGit
Hi,

On Thu, 17 Feb 2011, gmazza wrote:

> Hi, subject line says it all,

not that this is my name, but:

> every git command I enter within Git Bash requires me to keep typing in
> my ssh key passphrase. Is there a way I can enter the passphrase just
> once for a session and have it hold for all my git commands?

Maybe this helps?

https://git.wiki.kernel.org/index.php/GitTips#How_to_pass_ssh_options_in_git.3F

You need to generate the identity file with ssh-keygen.

Ciao,
Johannes

Erik Faye-Lund

unread,
Feb 17, 2011, 11:57:41 AM2/17/11
to gmazza, msysGit
On Thu, Feb 17, 2011 at 5:49 PM, gmazza <glen....@gmail.com> wrote:
> On Feb 17, 11:39 am, Erik Faye-Lund <kusmab...@gmail.com> wrote:
>> On Thu, Feb 17, 2011 at 5:23 PM, gmazza <glen.ma...@gmail.com> wrote:
>> > Hi, subject line says it all, every git command I enter within Git
>> > Bash requires me to keep typing in my ssh key passphrase.
>>
>> By "every git command" you mean "every git command that uses SSH
>> transport", right?
>>
>
> Yes.  10 git pulls require entering my passphrase 10 times, instead of
> ideally just once.
>

The good thing about distributed source control is that you don't need
to push or pull that often. But this might be of little comfort for
you those times you have to ;)

>> > Is there a
>> > way I can enter the passphrase just once for a session and have it
>> > hold for all my git commands?
>>
>> Yes, you need to install your ssh public key on the server. This is
>> usually a matter of running "ssh-keygen" and appending the content of
>> ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys file on the remote
>> machine. That way, you won't need to enter a password at all.
>
> I believe I've already done that--I use GitHub and this problem never
> occurs when I'm using Linux (just need to enter my passphrase once and
> that's good as long as I have the console window open.  It's just
> Windows and the GitBash shell that is having this problem, I'm not
> sure why.
>
> The passphrase is probably being used to sign my requests, so even
> with the public key on the server the GitHub client is still going to
> need to know that passphrase to do the signing.
>

When you made a ssh key, you were asked to protect it with a
passphrase. If you did, you're going to have to type the password
every single time. You probably didn't on Linux.

That's my psychic guess, anyway. Try to regenerate it, and this time
do not protect it. Replace the Github key for this machine. Then you
should get the same behavior as on Linux.

Erik Faye-Lund

unread,
Feb 17, 2011, 12:02:38 PM2/17/11
to Glen Mazza, Johan Herland, msy...@googlegroups.com
Please don't top-post. Fixed, and replied inline.

On Thu, Feb 17, 2011 at 5:55 PM, Glen Mazza <glen....@gmail.com> wrote:
> On 2/17/2011 11:47 AM, Johan Herland wrote:
>>
>> On Thursday 17 February 2011, gmazza wrote:
>>>
>>> Hi, subject line says it all, every git command I enter within Git
>>> Bash requires me to keep typing in my ssh key passphrase.  Is there a
>>> way I can enter the passphrase just once for a session and have it
>>> hold for all my git commands?
>>
>> http://lmgtfy.com/?q=Git+ssh+password+re-enter&l=1
>>
>

> Actually, I *did* go to that very page prior to asking my question--note
> that it is only valid for Linux and Mac OS.  I'm using, again, Windows.  So
> your lmgtfy was a miss.  :)
>

What makes you think that? The article even explicitly mentions
msysgit. It applies for Git for Windows as well.

Konstantin Khomoutov

unread,
Feb 17, 2011, 12:10:50 PM2/17/11
to gmazza, msysGit

Switch to public-key-based authentication and use a suitable
"authentication agent" to keep your decrypted key -- ssh-agent for
stock OpenSSH client of Pageant if you're using PuTTY as your SSH
client.

I'm using putty with pageant but just tried ssh-agent/ssh-add bundled
with Git and they do work, too (with Git bash as ssh-agent supposedly
cannot be used with cmd.exe).

Konstantin Khomoutov

unread,
Feb 17, 2011, 12:15:02 PM2/17/11
to gmazza, msysGit
On Thu, 17 Feb 2011 08:49:14 -0800 (PST)
gmazza <glen....@gmail.com> wrote:

[...]


> > > Is there a
> > > way I can enter the passphrase just once for a session and have it
> > > hold for all my git commands?
> > Yes, you need to install your ssh public key on the server. This is
> > usually a matter of running "ssh-keygen" and appending the content
> > of ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys file on the remote
> > machine. That way, you won't need to enter a password at all.
>
> I believe I've already done that--I use GitHub and this problem never
> occurs when I'm using Linux (just need to enter my passphrase once and
> that's good as long as I have the console window open. It's just
> Windows and the GitBash shell that is having this problem, I'm not
> sure why.

A typical Linux desktop has ssh-agent run somewhere early during the
desktop session startup, so you get it for free.

Johannes Schindelin

unread,
Feb 17, 2011, 12:16:30 PM2/17/11
to Erik Faye-Lund, gmazza, msysGit
Hi,

Well, it's probably the ssh-agent on Linux (which might be started up by
default in your bash session, depending on your distro) which prevents you
being asked too often.

Ciao,
Johannes

Glen Mazza

unread,
Feb 17, 2011, 1:40:05 PM2/17/11
to kusm...@gmail.com, Johan Herland, msy...@googlegroups.com

It is far from obvious that that page applies to Windows as well (a
search on the page for "Windows" turned up nothing, while it had
large-font references to Mac and Linux), further, it isn't clear that
what the page calls "mysisgit" is the same thing as the Git Bash shell
that I was running (it's titled an incomprehensible MINGW32 on the
console window), so I decided to ask on this mailing list instead.
Johan's lmgtfy wasn't appropriate here.

Glen

Erik Faye-Lund

unread,
Feb 17, 2011, 1:52:23 PM2/17/11
to Glen Mazza, Johan Herland, msy...@googlegroups.com
On Thu, Feb 17, 2011 at 7:40 PM, Glen Mazza <glen....@gmail.com> wrote:
> On 2/17/2011 12:02 PM, Erik Faye-Lund wrote:
>>
>> Please don't top-post. Fixed, and replied inline.
>>
>> On Thu, Feb 17, 2011 at 5:55 PM, Glen Mazza<glen....@gmail.com>  wrote:
>>>
>>> On 2/17/2011 11:47 AM, Johan Herland wrote:
>>>>
>>>> On Thursday 17 February 2011, gmazza wrote:
>>>>>
>>>>> Hi, subject line says it all, every git command I enter within Git
>>>>> Bash requires me to keep typing in my ssh key passphrase.  Is there a
>>>>> way I can enter the passphrase just once for a session and have it
>>>>> hold for all my git commands?
>>>>
>>>> http://lmgtfy.com/?q=Git+ssh+password+re-enter&l=1
>>>>
>>> Actually, I *did* go to that very page prior to asking my question--note
>>> that it is only valid for Linux and Mac OS.  I'm using, again, Windows.
>>>  So
>>> your lmgtfy was a miss.  :)
>>>
>> What makes you think that? The article even explicitly mentions
>> msysgit. It applies for Git for Windows as well.
>
> It is far from obvious that that page applies to Windows as well (a search
> on the page for "Windows" turned up nothing, while it had large-font
> references to Mac and Linux),

GitHub usually treats all OS'es equally. Not explicitly mentioning
Windows should thus be taken as an indication of it working on
Windows.

> further, it isn't clear that what the page
> calls "mysisgit" is the same thing as the Git Bash shell that I was running
> (it's titled an incomprehensible MINGW32 on the console window), so I
> decided to ask on this mailing list instead.

It calls it "msysgit", which is the name of the project who develops
Git for Windows. And it also happens to be the name of this mailing
list. I think that should have been a good enough clue.

> Johan's lmgtfy wasn't
> appropriate here.
>

But it was. It describes how to solve your problem in depth, and it is
the Google-hit with trivial keywords. Get over it, and read the
article so you can get your problem solved :)

Johannes Schindelin

unread,
Feb 17, 2011, 3:26:34 PM2/17/11
to Glen Mazza, msy...@googlegroups.com
Hi Glen,

On Thu, 17 Feb 2011, Glen Mazza wrote:

> Johan's lmgtfy wasn't appropriate here.

If you want to get help in the future, you might want to reconsider the
wording of your replies. I understand that you are frustrated, but it does
no good to turn frustration against those precious few who are ready to
try to assist. For free, no less.

Hth,
Johannes

Glen Mazza

unread,
Feb 17, 2011, 5:51:29 PM2/17/11
to msy...@googlegroups.com
On 2/17/2011 1:52 PM, Erik Faye-Lund wrote:
>
> But it was. It describes how to solve your problem in depth, and it is
> the Google-hit with trivial keywords. Get over it, and read the
> article so you can get your problem solved :)

OK, I placed the code listed right under the "Auto-launching ssh-agent
on msysgit" section[1] in my ~/.bashrc file on Windows, and each time I
start the Git Bash shell I know it is reading that file (to check, I
changed the value of SSH_ENV and then typed echo $SSH_ENV in the shell
to confirmed it read the new value). But each time I start GitHub it
says "Could not open a connection to your authentication agent". Typing
the command "ssh-agent" within the Git Bash shell does appear to execute
a program of that name, so it apparently does have ssh-agent, so I'm not
sure what I'm doing wrong here.

I'll try to use Putty with the Git Bash shell[2], maybe that will work.

[1] http://help.github.com/working-with-key-passphrases/
[2] http://nathanj.github.com/gitguide/tour.html

Glen

Glen Mazza

unread,
Feb 17, 2011, 6:31:09 PM2/17/11
to msy...@googlegroups.com

I got it working now--I didn't need Putty, my problem was multiple
ssh-agent processes running in the background causing a conflict.
Killing those processes and restarting the Git Bash shell fixed it. The
code in [1] works fine, as-is. Thanks everyone.

Glen

Konstantin Khomoutov

unread,
Feb 17, 2011, 6:42:07 PM2/17/11
to Glen Mazza, msy...@googlegroups.com
On Thu, Feb 17, 2011 at 05:51:29PM -0500, Glen Mazza wrote:

> >But it was. It describes how to solve your problem in depth, and it is
> >the Google-hit with trivial keywords. Get over it, and read the
> >article so you can get your problem solved :)
>
> OK, I placed the code listed right under the "Auto-launching
> ssh-agent on msysgit" section[1] in my ~/.bashrc file on Windows,
> and each time I start the Git Bash shell I know it is reading that
> file (to check, I changed the value of SSH_ENV and then typed echo
> $SSH_ENV in the shell to confirmed it read the new value). But each
> time I start GitHub it says "Could not open a connection to your
> authentication agent". Typing the command "ssh-agent" within the
> Git Bash shell does appear to execute a program of that name, so it
> apparently does have ssh-agent, so I'm not sure what I'm doing wrong
> here.

I did my testing mentioned earlier in this thread this way:

$ eval `ssh-agent -s`
$ ssh-add '/c/document and settings/user/my_key.pem'

I suggest trying this first if you need ssh-agent for some reason.

Reply all
Reply to author
Forward
0 new messages