From afa6b31844e00f18a3d0c76876d587927ae5bec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Thu, 25 Mar 2021 10:52:35 +0100 Subject: [PATCH] Import workaround to configure hosts with non-standard SSH port --- remote-copy-custom-port.sh | 23 +++++++++++++++++++++++ remote-exec-custom-port.sh | 16 ++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 remote-copy-custom-port.sh create mode 100755 remote-exec-custom-port.sh diff --git a/remote-copy-custom-port.sh b/remote-copy-custom-port.sh new file mode 100755 index 0000000..1cc8082 --- /dev/null +++ b/remote-copy-custom-port.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# +# Workaround to configure hosts with SSH servers listening on non-standard +# ports (e.g. IPv4-only VMs hidden behind a NAT). It'll blow up with IPv6 +# addresses and might burn your house. + +set -x + +target_host=$(echo "$@" | rev | cut -d ' ' -f1 | rev) +args=$(echo "$@" | rev | cut -d ' ' -f1 --complement | rev) + +name=$(echo $target_host | cut -d ':' -f 1) +port_or_path=$(echo $target_host | cut -d ':' -f 2) +path=$(echo $target_host | cut -d ':' -f 3) + +addr=$name:$port_or_path +scp_extra_params= +if [ -n "$path" ]; then + addr=$name:$path + scp_extra_params="-P $port_or_path" +fi + +scp -o User=root -q $scp_extra_params $args $addr diff --git a/remote-exec-custom-port.sh b/remote-exec-custom-port.sh new file mode 100755 index 0000000..f086649 --- /dev/null +++ b/remote-exec-custom-port.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# +# Workaround to configure hosts with SSH servers listening on non-standard +# ports (e.g. IPv4-only VMs hidden behind a NAT). It'll blow up with IPv6 +# addresses and might burn your house. + +target_host=$1; shift +name=$(echo $target_host | cut -d ':' -f 1) +port=$(echo $target_host | cut -d ':' -s -f 2) + +ssh_extra_params= +if [ -n "$port" ]; then + ssh_extra_params="-p $port" +fi + +ssh -o User=root $ssh_extra_params $name $@