@@ -23,6 +23,7 @@ function openssh() {
23
23
tunnel_method=$( cat $1 | jq -r ' .tunnel_map.tunnel_method' | tr ' [:lower:]' ' [:upper:]' )
24
24
tunnel_username=$( cat $1 | jq -r ' .tunnel_map.tunnel_user' )
25
25
tunnel_host=$( cat $1 | jq -r ' .tunnel_map.tunnel_host' )
26
+ tunnel_port=$( cat $1 | jq -r ' .tunnel_map.tunnel_port' )
26
27
tunnel_local_port=$( cat $1 | jq -r ' .local_port' )
27
28
# set a path for a control socket, allowing us to close this specific ssh connection when desired
28
29
tmpcontrolsocket=" /tmp/sshsocket${tunnel_db_remote_port} -${RANDOM} "
@@ -33,8 +34,8 @@ function openssh() {
33
34
tmpkeyfile=$( mktemp /tmp/xyzfile.XXXXXXXXXXX) || return 1
34
35
cat $1 | jq -r ' .tunnel_map.ssh_key | gsub("\\\\n"; "\n")' > $tmpkeyfile
35
36
# -f=background -N=no remote command -M=master mode StrictHostKeyChecking=no auto-adds host
36
- echo " Running: ssh -f -N -M -o StrictHostKeyChecking=no -S {control socket} -i {key file} -l ${tunnel_username} -L ${tunnel_local_port} :${tunnel_db_host} :${tunnel_db_port} ${tunnel_host} "
37
- ssh -f -N -M -o StrictHostKeyChecking=no -S $tmpcontrolsocket -i $tmpkeyfile -l ${tunnel_username} -L ${tunnel_local_port} :${tunnel_db_host} :${tunnel_db_port} ${tunnel_host} &&
37
+ echo " Running: ssh -f -N -M -o StrictHostKeyChecking=no -S {control socket} -i {key file} -l ${tunnel_username} -L ${tunnel_local_port} :${tunnel_db_host} :${tunnel_db_port} -p ${tunnel_port } ${tunnel_host} "
38
+ ssh -f -N -M -o StrictHostKeyChecking=no -S $tmpcontrolsocket -i $tmpkeyfile -l ${tunnel_username} -L ${tunnel_local_port} :${tunnel_db_host} :${tunnel_db_port} -p ${tunnel_port } ${tunnel_host} &&
38
39
sshopen=" yes" &&
39
40
echo " ssh tunnel opened"
40
41
rm -f $tmpkeyfile
@@ -49,8 +50,8 @@ function openssh() {
49
50
fi
50
51
# put ssh password in env var for use in sshpass. Better than directly passing with -p
51
52
export SSHPASS=$( cat $1 | jq -r ' .tunnel_map.tunnel_user_password' )
52
- echo " Running: sshpass -e ssh -f -N -M -o StrictHostKeyChecking=no -S {control socket} -l ${tunnel_username} -L ${tunnel_local_port} :${tunnel_db_host} :${tunnel_db_port} ${tunnel_host} "
53
- sshpass -e ssh -f -N -M -o StrictHostKeyChecking=no -S $tmpcontrolsocket -l ${tunnel_username} -L ${tunnel_local_port} :${tunnel_db_host} :${tunnel_db_port} ${tunnel_host} &&
53
+ echo " Running: sshpass -e ssh -f -N -M -o StrictHostKeyChecking=no -S {control socket} -l ${tunnel_username} -L ${tunnel_local_port} :${tunnel_db_host} :${tunnel_db_port} -p ${tunnel_port} ${tunnel_host} "
54
+ sshpass -e ssh -f -N -M -o StrictHostKeyChecking=no -S $tmpcontrolsocket -l ${tunnel_username} -L ${tunnel_local_port} :${tunnel_db_host} :${tunnel_db_port} -p ${tunnel_port} ${tunnel_host} &&
54
55
sshopen=" yes" &&
55
56
echo " ssh tunnel opened"
56
57
fi
@@ -61,7 +62,7 @@ function openssh() {
61
62
function closessh() {
62
63
# $sshopen $tmpcontrolsocket comes from openssh() function
63
64
if [ ! -z " $sshopen " ] ; then
64
- ssh -S $tmpcontrolsocket -O exit ${tunnel_host} &&
65
+ ssh -S $tmpcontrolsocket -O exit -p ${tunnel_port} ${tunnel_host} &&
65
66
echo " closed ssh tunnel"
66
67
trap ' rm -f "$tmpcontrolsocket"' EXIT
67
68
fi
0 commit comments