summaryrefslogtreecommitdiff
path: root/src/monkeysphere-ssh-proxycommand
blob: ec162ab8c62985d92bf82eb0e8a0eccb120abc6b (plain)
  1. #!/bin/sh -e
  2. # monkeysphere-ssh-proxycommand: MonkeySphere ssh ProxyCommand hook
  3. #
  4. # The monkeysphere scripts are written by:
  5. # Jameson Rollins <jrollins@fifthhorseman.net>
  6. #
  7. # They are Copyright 2008, and are all released under the GPL, version 3
  8. # or later.
  9. # This is meant to be run as an ssh ProxyCommand to initiate a
  10. # monkeysphere known_hosts update before an ssh connection to host is
  11. # established. Can be added to ~/.ssh/config as follows:
  12. # ProxyCommand monkeysphere-ssh-proxycommand %h %p
  13. HOST="$1"
  14. PORT="$2"
  15. usage() {
  16. cat <<EOF >&2
  17. usage: ssh -o ProxyCommand="$(basename $0) %h %p" ...
  18. EOF
  19. }
  20. log() {
  21. echo "$@" >&2
  22. }
  23. if [ -z "$HOST" ] ; then
  24. log "host must be specified."
  25. usage
  26. exit 1
  27. fi
  28. if [ -z "$PORT" ] ; then
  29. log "port must be specified."
  30. usage
  31. exit 1
  32. fi
  33. # check for the host key in the known_hosts file
  34. hostKey=$(ssh-keygen -F "$HOST")
  35. # if the host key is not found in the known_hosts file,
  36. # check the keyserver
  37. if [ -z "$hostKey" ] ; then
  38. CHECK_KEYSERVER="true"
  39. fi
  40. # update the known_hosts file for the host
  41. monkeysphere update-known-hosts "$HOST"
  42. # exec a netcat passthrough to host for the ssh connection
  43. exec nc "$HOST" "$PORT"