Skip to content

Instantly share code, notes, and snippets.

@huangsam
Created September 20, 2019 16:19
Show Gist options
  • Save huangsam/5318c0fd1b2edbd38034316b2563e701 to your computer and use it in GitHub Desktop.
Save huangsam/5318c0fd1b2edbd38034316b2563e701 to your computer and use it in GitHub Desktop.
Bash function for creating a SSH tunnel
function ssh_tunnel() {
target_host="$1"
target_port="$2"
tunnel_host="$3"
source_port="$4"
[[ `ps axu | grep $target_port | grep ssh` ]] && return
ssh -Nf -L "$source_port:$target_host:$target_port" "$tunnel_host"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment