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