From a0b1a995f68ad81cf10cea3ea778708754793b54 Mon Sep 17 00:00:00 2001 From: Oliver Ladner Date: Tue, 3 May 2022 09:26:56 +0200 Subject: [PATCH] add SSH tunneling script --- sshtunnel.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 sshtunnel.sh diff --git a/sshtunnel.sh b/sshtunnel.sh new file mode 100755 index 0000000..8b90ae0 --- /dev/null +++ b/sshtunnel.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Allows to access some web UIs through VPN + +function sshtunnel { + target=$1 + + # get occupied ports by SSH sessions + local_used_ports=$(lsof -PiTCP -sTCP:LISTEN | grep ssh | awk -F':' '{print $2}' | uniq | grep -Eo '[0-9]{1,5}') + + # define a port + local_selected_port=$(shuf -n 1 <(seq 60000 | grep -Fxv -e{$local_used_ports})) + + echo "$target: https://localhost:$local_selected_port" + ssh -L $local_selected_port:$target:443 oli@10.7.1.90 +} + +sshtunnel $1