ssh-askpass on OSX 10.5

I’ve been playing with NetBeans 6.7M3 and the latest Mercurial plugin and found that I couldn’t push to a remote repository via ssh. All netbeans would return was:

Mercurial Push
--------------
INFO Pushing To: ssh://pmount@lego.office.gameaccount.com/hg/ga4Partner ...
ERROR Command failed:
Command: [/usr/local/bin/hg, outgoing, -v, --template=rev:{rev}\nauth:{author}\ndesc:{desc}\ndate:{date|hgdate}\nid:{node|short}\n\nendCS:\n, --repository, /Users/peter/dev/gameaccount/maven/ga4Partner, ssh://pmount@lego.office.gameaccount.com/hg/ga4Partner]
Output: [running ssh pmount@lego.office.gameaccount.com “hg -R hg/ga4Partner serve --stdio”, remote: ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory, remote: Host key verification failed., abort: no suitable response from remote hg!]
INFO: End of Mercurial Push

Here the remote server is trying to prompt for the login password but fails because OSX 10.5 does not have the ssk-askpass command.

After some searching on the net (ok Google who else) I found Mercurial Push from IntelliJ where someone had a similar position with IntelliJ. By creating the following script mercurial in NB6.7M3 works flawlessly:

sabrina:~ peter$ sudo vi /usr/libexec/ssh-askpass
#! /bin/sh  
  
#  
# An SSH_ASKPASS command for MacOS X  
#  
# Author: Joseph Mocker, Sun Microsystems  
  
#  
# To use this script:  
#     setenv SSH_ASKPASS "macos-askpass"  
#     setenv DISPLAY ":0"  
#  
  
TITLE=${MACOS_ASKPASS_TITLE:-"SSH"}  
  
DIALOG="display dialog \"$@\" default answer \"\" with title \"$TITLE\""  
DIALOG="$DIALOG with icon caution with hidden answer"  
  
result=`osascript -e 'tell application "Finder"' -e "activate"  -e "$DIALOG" -e 'end tell'`  
  
if [ "$result" = "" ]; then  
    exit 1  
else  
    echo "$result" | sed -e 's/^text returned://' -e 's/, button returned:.*$//'  
    exit 0  
fi  

sabrina:~ peter$ sudo chmod +x /usr/libexec/ssh-askpass
Advertisements

24 Comments

  1. Thanks, I'll fix the article shortly. It's a problem with using MacJournal in the past where it keeps using Unicode quotes instead of ASCII ones – that and the horrible html it generates.

  2. This fails if you have any 32-bit extension on 64-bit Snow Leopard.

    On line 20, you should rather use “arch -i386 osascript …”

    The source of my 64-bit problem was Adobe’s software,
    so I decided to use “arch -i386 osascript …”.

    There are another solutions for this specific Adobe’s problem:
    http://kb2.adobe.com/cps/516/cpsid_51615.html

  3. Yes, when I originally wrote this Snow Leopard wasn’t available and so far have not yet been able to upgrade due to a couple of software dependencies that don’t work with it.

    Hopefully by the end of the month I’ll have sorted those two out so would have hit this problem myself.

    Thanks for the tip.

  4. If you are using MercurialEclipse or a single Login (credential) you can hard-code the password in the ssh-askpass file itself,

    eg:

    ! /bin/sh
    echo “your password” | sed -e ‘s/^text returned://’ -e ‘s/, button returned:.*$//’

  5. This was an awesome fix! I use ClusterIT to manage a cluster of linux nodes. After my 10.7 upgrade, I was missing ‘known-hosts’ for the linux nodes. Your script prompted me to add, and now dsh is working again. Excellent!

  6. Thank you so much, this is exactly what makes hgEclipse aka MercurialEclipse run smoothly in Zend Studio 8, Zend Studio 9 on Lion 10.7.3. Without it I just got the “No suitable response from hg!” Error

    Thanks for sharing.

  7. Way cool and thanks – I changed the script to use the current terminal application to generate the Ui from instead of Finder – on my Mac that keeps the focus on the terminal application even if the terminal is in full screen (for example, with iTerm if I use Finder to generate the dialog then the dialog appears behind the terminal screen – whereas if I use iTerm then the dialog is placed in front of the full-screen terminal).

    1. And how did you accomplish that? My google-fu is weak I can’t find how to display an independent dialog. I can send the “display dialog” command to my terminal instead, but hardcoding “iTerm” into the script is a little hackish.

      1. Hi Xam,

        Here’s my script … yeah, I hard-coded iTerm into my variant because that is the only terminal I use on my Mac.

        #!/bin/bash
        #
        # An SSH_ASKPASS command for MacOS X
        #
        # Author: Joseph Mocker, Sun Microsystems

        #
        # To use this script:
        # setenv SSH_ASKPASS “macos-askpass”
        # setenv DISPLAY “:0”
        #

        TITLE=${MACOS_ASKPASS_TITLE:-“SSH”}

        DIALOG=’display dialog “‘”$@”‘” default answer “” with title “‘”$TITLE”‘”‘
        DIALOG+=” with icon caution with hidden answer”

        result=$( osascript -e ‘tell application “iTerm”‘ -e “activate” -e “$DIALOG” -e ‘end tell’ )

        if [ “$result” = “” ]
        then
        exit 1
        else
        echo “$result” | sed -e ‘s/^text returned://’ -e ‘s/, button returned:.*$//’
        exit 0
        fi

      2. Hi Xam – yeah, I used the hackish way :):

        #!/bin/bash
        #
        # An SSH_ASKPASS command for MacOS X
        #
        # Author: Joseph Mocker, Sun Microsystems

        #
        # To use this script:
        # setenv SSH_ASKPASS “macos-askpass”
        # setenv DISPLAY “:0”
        #

        TITLE=${MACOS_ASKPASS_TITLE:-“SSH”}

        DIALOG=’display dialog “‘”$@”‘” default answer “” with title “‘”$TITLE”‘”‘
        DIALOG+=” with icon caution with hidden answer”

        result=$( osascript -e ‘tell application “iTerm”‘ -e “activate” -e “$DIALOG” -e ‘end tell’ )

        if [ “$result” = “” ]
        then
        exit 1
        else
        echo “$result” | sed -e ‘s/^text returned://’ -e ‘s/, button returned:.*$//’
        exit 0
        fi

  8. For those of you using Mavericks (10.9), this script stopped working because Apple changed the order in which the Finder dialog returns information to the script. Instead of returning “text returned:, button returned:OK” it now returns “button returned:OK, text returned:”.

    I changed the third line from the end of the script to:
    echo “$result” | sed -e ‘s/^button returned:OK, text returned://’

    And then it started working again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s