Skip to content

Instantly share code, notes, and snippets.

@petiepooo
Created January 6, 2017 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petiepooo/cf5e943b31856b45794ebe79fa497cf8 to your computer and use it in GitHub Desktop.
Save petiepooo/cf5e943b31856b45794ebe79fa497cf8 to your computer and use it in GitHub Desktop.
OSX 10.9 script to allow confirmation of ssh keys on each use (/usr/libexec/ssh-askpass)
#!/bin/bash
#
# An SSH_ASKPASS command for MacOS X
#
# Author: petiepooo
# License: CC_SA
#
# This script is called by ssh-agent when SSH_ASKPASS environment
# variable is set. It allows use of confirm each use when adding
# an ssh key (ssh-add -c <key>).
#
# if the first argument is '-s', output shell commands for eval
if [ "$1" == "-s" ]; then
echo "SSH_ASKPASS=/usr/libexec/ssh-askpass"
echo "export SSH_ASKPASS"
exit 0
fi
# find the frontmost application at time of execution
FRAPP=`osascript -e 'tell application "System Events"'\
-e 'set result to name of first application process\
whose frontmost is true' -e 'end tell'`
# build the dialog command
DIALOG="display dialog \"$@\" default answer \"\"\
with hidden answer with icon caution\
with title \"${SSH_ASKPASS_TITLE:-"SSH"}\""
if [ "$FRAPP" != "Terminal" ]; then
say "s s h authentication request" &
fi
result=`osascript -e 'tell application "Terminal"'\
-e "$DIALOG" -e 'text returned of result' -e 'end tell' 2>/dev/null`
return=$?
# return the text entered in the password entry field as stdout
test -z "$result" && exit $return
# else return the password entered on stdout
exec echo "$result" | sed -e 's/^text returned://' -e 's/, button.*$//'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment