Import workaround to configure hosts with non-standard SSH port

This commit is contained in:
Timothée Floure 2021-03-25 10:52:35 +01:00
parent 6e2130b305
commit afa6b31844
Signed by: tfloure
GPG Key ID: 4502C902C00A1E12
2 changed files with 39 additions and 0 deletions

23
remote-copy-custom-port.sh Executable file
View File

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

16
remote-exec-custom-port.sh Executable file
View File

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