How to enter ssh passphrase when pushing remote branches

426 views
Skip to first unread message

phtrivier

unread,
Dec 14, 2009, 6:08:46 PM12/14/09
to magit
Hi, i am using magit to interface with a github repository, for which
I configured my ssh key.

When I want to git push to it, I normally have to enter my ssh key
passphrase. However when pushing from magit, I don't get prompted for
my passphrase.

I tried displaying the git output (using '$'), and it shows the
prompt, but the buffer is read-only and I cannot edit it (I also tried
toggling the read-only property, with no success).

Is it possible to have magit ask for the ssh passphrase in emacs
minibuffer ?

Thanks
PH

Rémi Vanicat

unread,
Dec 15, 2009, 2:01:10 AM12/15/09
to ma...@googlegroups.com
It's a bug: we don't tell ssh that it can't ask for passphrase there.

You will found there :
http://gitorious.org/~__DL__/magit/remi-magit-clone/commits/ssh-asking
a patched version that do it better. This need testing (I have change
the way magit run git, and I believe that it won't change anything, but
testing will prove it).

It would be probably better to detect the passphrase asking, and to use
Emacs to ask for it, but this is a more complicated fix. If someone
could do it, it would be great.

Here is the fixing commit:

commit 213bd29c793b2904b29a01a9c8448e4f9b4c4823
Author: Rémi Vanicat <van...@debian.org>
Date: Tue Dec 15 07:42:57 2009 +0100

Use pipe rather than tty for connection with git.

When remote updating, git may use ssh that may ask for a password or
passphrase. ssh used to be on a tty, and so believe that it could ask
the passphrase directly to the user. It now know that it can't, and
will ssh-askpass (if available) to do the asking.

It would be probably better to detect the passphrase asking, and to
use Emacs to ask for it.

diff --git a/magit.el b/magit.el
index bfbfe9b..a035ebe 100644
--- a/magit.el
+++ b/magit.el
@@ -1004,7 +1004,8 @@ Many Magit faces inherit from this one by default."
(args (cdr cmd-and-args))
(dir default-directory)
(buf (get-buffer-create "*magit-process*"))
- (successp nil))
+ (successp nil)
+ (process-connection-type nil))
(magit-set-mode-line-process
(magit-process-indicator-from-command cmd-and-args))
(setq magit-process-client-buffer (current-buffer))



--
Rémi Vanicat

phtrivier

unread,
Dec 15, 2009, 4:34:12 AM12/15/09
to magit
Thanks, it worked fine !

On 15 déc, 08:01, vani...@debian.org (Rémi Vanicat) wrote:
> phtrivier <phtriv...@gmail.com> writes:
> > Hi, i am using magit to interface with a github repository, for which
> > I configured my ssh key.
>
> > When I want to git push to it, I normally have to enter my ssh key
> > passphrase. However when pushing from magit, I don't get prompted for
> > my passphrase.
>
> > I tried displaying the git output (using '$'), and it shows the
> > prompt, but the buffer is read-only and I cannot edit it (I also tried
> > toggling the read-only property, with no success).
>
> > Is it possible to have magit ask for the ssh passphrase in emacs
> > minibuffer ?
>
> It's a bug: we don't tell ssh that it can't ask for passphrase there.
>
> You will found there :http://gitorious.org/~__DL__/magit/remi-magit-clone/commits/ssh-asking
> a patched version that do it better. This need testing (I have change
> the way magit run git, and I believe that it won't change anything, but
> testing will prove it).
>
> It would be probably better to detect the passphrase asking, and to use
> Emacs to ask for it, but this is a more complicated fix. If someone
> could do it, it would be great.
>
> Here is the fixing commit:
>
> commit 213bd29c793b2904b29a01a9c8448e4f9b4c4823
> Author: Rémi Vanicat <vani...@debian.org>

Rüdiger Sonderfeld

unread,
Dec 15, 2009, 1:40:16 PM12/15/09
to magit
Hi,
I just wrote a quick fix for it. That asks for the password. It needs
some testing and magit-password should check if the Enter thing is
really the second line after the "$ git" line.

If you don't want to apply this highly experimental patch and find
yourself in a situation where magit "hangs" because a process is
running. Switch to the process buffer ($) and kill it (C-x k) and
confirm with yes. This should help.

Regards,
Rüdiger <rued...@c-plusplus.de>

P.S. magit is really great. I love using it!

Changes in HEAD
Modified magit.el
diff --git a/magit.el b/magit.el
index bfbfe9b..7c694f5 100644
--- a/magit.el
+++ b/magit.el
@@ -1074,10 +1074,20 @@ Many Magit faces inherit from this one by
default."
(magit-set-mode-line-process nil)
(magit-refresh-buffer magit-process-client-buffer)))

+(defun magit-password (proc string)
+ "Checks if git/ssh asks for a password and ask the user for it."
+ (when (string-match "^Enter passphrase for key '\\\(.*\\\)': $"
string)
+ (process-send-string proc
+ (concat (read-passwd
+ (format "Password for '%s':
" (match-string 1 string))
+ nil) "\n"))))
+
(defun magit-process-filter (proc string)
(save-current-buffer
(set-buffer (process-buffer proc))
(let ((inhibit-read-only t))
+ (magit-password proc string)
(goto-char (process-mark proc))
;; Find last ^M in string. If one was found, ignore everything
;; before it and delete the current line.



On Dec 15, 8:01 am, vani...@debian.org (Rémi Vanicat) wrote:
> phtrivier <phtriv...@gmail.com> writes:
> > Hi, i am using magit to interface with a github repository, for which
> > I configured my ssh key.
>
> > When I want to git push to it, I normally have to enter my ssh key
> > passphrase. However when pushing from magit, I don't get prompted for
> > my passphrase.
>
> > I tried displaying the git output (using '$'), and it shows the
> > prompt, but the buffer is read-only and I cannot edit it (I also tried
> > toggling the read-only property, with no success).
>
> > Is it possible to have magit ask for the ssh passphrase in emacs
> > minibuffer ?
>
> It's a bug: we don't tell ssh that it can't ask for passphrase there.
>
> You will found there :http://gitorious.org/~__DL__/magit/remi-magit-clone/commits/ssh-asking
> a patched version that do it better. This need testing (I have change
> the way magit run git, and I believe that it won't change anything, but
> testing will prove it).
>
> It would be probably better to detect the passphrase asking, and to use
> Emacs to ask for it, but this is a more complicated fix. If someone
> could do it, it would be great.
>
> Here is the fixing commit:
>
> commit 213bd29c793b2904b29a01a9c8448e4f9b4c4823
> Author: Rémi Vanicat <vani...@debian.org>

David Abrahams

unread,
Jan 6, 2010, 4:29:14 PM1/6/10
to Rüdiger Sonderfeld, magit

Is this fix being integrated?

--
Dave Abrahams Meet me at BoostCon: http://www.boostcon.com
BoostPro Computing
http://www.boostpro.com

Ross A. Laird

unread,
Feb 22, 2010, 8:48:21 PM2/22/10
to ma...@googlegroups.com

David Abrahams <da...@boostpro.com> writes:


This would be great for me; however, I am a writer (for whom version
control is a god-send) and not a programmer, so I do not know how to
patch my version of magit with this fix.

Suggestions are welcome.

Cheers.

Ross

--
Ross A. Laird, PhD
www.rosslaird.com

Rémi Vanicat

unread,
Feb 23, 2010, 2:12:25 AM2/23/10
to ma...@googlegroups.com

You could find it there: http://gitorious.org/magit/remi-magit-clone/archive-tarball/ssh-ask-pass

By the way I made a merge request for it in mainline, one could hope it
will be in magit official package soon.

--
Rémi Vanicat

Reply all
Reply to author
Forward
0 new messages