Skip to content

Commit ebd9dec

Browse files
committed
fix: Handle non-standart SSH port
1 parent 793db8e commit ebd9dec

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

docker-pussh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,37 @@ declare -a SSH_ARGS=()
6565
# It populates the SSH_ARGS array with arguments for reuse.
6666
ssh_remote() {
6767
local ssh_addr="$1"
68+
local target port
69+
# Split out the port component, if exists
70+
if [[ "$ssh_addr" =~ ^([^:]+)(:([0-9]+))?$ ]]; then
71+
target="${BASH_REMATCH[1]}"
72+
port="${BASH_REMATCH[3]:-22}" # Default port is 22 if not specified
73+
else
74+
error "Invalid SSH address format. Expected format: [USER@]HOST[:PORT]"
75+
fi
76+
6877
local ssh_opts=(
6978
-o ControlMaster=auto
7079
# Unique control socket path for this invocation.
7180
-o "ControlPath=/tmp/docker-pussh-$$.sock"
7281
# The connection will be automatically terminated after 1 minute of inactivity.
7382
-o ControlPersist=1m
7483
-o ConnectTimeout=15
84+
-p "${port}"
7585
)
7686
# Add SSH key option if provided.
7787
if [ -n "$SSH_KEY" ]; then
7888
ssh_opts+=(-i "$SSH_KEY")
7989
fi
8090

8191
# Establish ControlMaster connection in the background.
82-
if ! ssh "${ssh_opts[@]}" -f -N "$ssh_addr"; then
92+
if ! ssh "${ssh_opts[@]}" -f -N "${target}"; then
8393
error "Failed to connect to remote host via SSH: $ssh_addr"
8494
fi
8595

8696
# Populate SSH_ARGS array for reuse in all subsequent commands.
8797
SSH_ARGS=("${ssh_opts[@]}")
88-
SSH_ARGS+=("$ssh_addr")
98+
SSH_ARGS+=("${target}")
8999
}
90100

91101
# sudo prefix for remote docker commands. It's set to "sudo" if the remote user is not root and requires sudo

0 commit comments

Comments
 (0)