dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles # fast
git clone https://src.adamsgaard.dk/dotfiles.git # slow
Log | Files | Refs | README | LICENSE Back to index

ssh-tunnel-adamsgaard (570B)


      1 #!/bin/sh
      2 # add some cron entry to keep the tunnel alive across reconnects:
      3 # */2 *  * * *  ~/.local/bin/ssh-tunnel-adamsgaard >/dev/null 2>&1
      4 remote="adamsgaard.dk"
      5 identity="~/.ssh/id_rsa_ad"
      6 
      7 die() {
      8 	printf '%s: error: %s\n' "$1" >&2
      9 	exit 1
     10 }
     11 
     12 create_tunnel() {
     13 	if ssh -i "$identity" -f -N -R 10022:localhost:22 -L19922:"$remote":22 "$remote" >/dev/null; then
     14 		printf 'tunnel to %s created successfully\n' "$remote"
     15 	else
     16 		die "could not create tunnel to $remote ($?)"
     17 	fi
     18 }
     19 
     20 if ! ssh -i "$identity" -p 19922 localhost ls >/dev/null 2>&1; then
     21 	create_tunnel
     22 fi