summaryrefslogtreecommitdiff
path: root/localautossh
blob: e9d849d4eebb453785b3877f0a2f1ae3a9c4906e (plain)
  1. #!/bin/sh
  2. #
  3. # Example script to start up tunnel with autossh.
  4. #
  5. # This script will tunnel 2200 from the remote host
  6. # to 22 on the local host. On remote host do:
  7. # ssh -p 2200 localhost
  8. #
  9. # Recommends: notify-bin
  10. set -e
  11. action="$1"
  12. remotehost="$2"
  13. remoteport="${3:-2200}"
  14. info() {
  15. if [ -n "$DISPLAY" ] && [ -e /usr/bin/notify-send ]; then
  16. notify-send "$1" "$2"
  17. else
  18. echo >&2 "$1"
  19. echo >&2 "$2"
  20. fi
  21. }
  22. case "$action" in
  23. start)
  24. info "Starting remote help..." "Establishing a connection tunnel from $remotehost into this machine..."
  25. ;;
  26. stop)
  27. killall -KILL autossh
  28. info "Remote help is off!" "Connection tunnels into this machine is now inactive."
  29. exit $?
  30. ;;
  31. *)
  32. echo 2>& "Wrong action passed to localautossh!"
  33. exit 1
  34. ;;
  35. esac
  36. if [ -z "$SSH_ASKPASS" ]; then
  37. export SSH_ASKPASS="ssh-askpass"
  38. fi
  39. if [ "X$SSH_AUTH_SOCK" = "X" ]; then
  40. eval `ssh-agent -s`
  41. ssh-add $HOME/.ssh/id_rsa
  42. fi
  43. #AUTOSSH_POLL=600
  44. #AUTOSSH_PORT=20000
  45. #AUTOSSH_GATETIME=30
  46. #AUTOSSH_LOGFILE=$HOST.log
  47. #AUTOSSH_DEBUG=yes
  48. #AUTOSSH_PATH=/usr/local/bin/ssh
  49. export AUTOSSH_POLL AUTOSSH_LOGFILE AUTOSSH_DEBUG AUTOSSH_PATH AUTOSSH_GATETIME AUTOSSH_PORT
  50. autossh -2 -f -o BatchMode=yes -N -M 20000 -R $remoteport:localhost:22 "$remotehost"
  51. info "Remote help is on!" "Connection tunnel from $remotehost into this machine is now active."