Skip to content

Commit dfbb0fd

Browse files
authored
Merge pull request #455 from analytically/feature/ports
fix: handle custom SSH ports in ssh:// URLs
2 parents c2672aa + d252b2d commit dfbb0fd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

assets/common.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ load_pubkey() {
66
local private_key_user=$(jq -r '.source.private_key_user // empty' <<< "$1")
77
local forward_agent=$(jq -r '.source.forward_agent // false' <<< "$1")
88
local passphrase="$(jq -r '.source.private_key_passphrase // empty' <<< "$1")"
9+
local uri=$(jq -r '.source.uri // ""' <<< "$1")
910

1011
(jq -r '.source.private_key // empty' <<< "$1") > $private_key_path
1112

@@ -22,16 +23,31 @@ load_pubkey() {
2223
StrictHostKeyChecking no
2324
LogLevel quiet
2425
EOF
26+
27+
# Handle ssh:// URLs with custom ports
28+
if [[ "$uri" =~ ^ssh://([^@]+@)?([^:/]+):([0-9]+) ]]; then
29+
local ssh_host="${BASH_REMATCH[2]}"
30+
local ssh_port="${BASH_REMATCH[3]}"
31+
32+
cat >> ~/.ssh/config <<EOF
33+
34+
Host $ssh_host
35+
Port $ssh_port
36+
EOF
37+
fi
38+
2539
if [ ! -z "$private_key_user" ]; then
2640
cat >> ~/.ssh/config <<EOF
2741
User $private_key_user
2842
EOF
2943
fi
44+
3045
if [ "$forward_agent" = "true" ]; then
3146
cat >> ~/.ssh/config <<EOF
3247
ForwardAgent yes
3348
EOF
3449
fi
50+
3551
chmod 0600 ~/.ssh/config
3652
fi
3753
}

0 commit comments

Comments
 (0)