add SSH tunneling script

This commit is contained in:
Oliver Ladner 2022-05-03 09:26:56 +02:00
commit a0b1a995f6

17
sshtunnel.sh Executable file
View file

@ -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