From 69131534fe9525158bb873b825b4623d2bd95056 Mon Sep 17 00:00:00 2001 From: MatMoul Date: Tue, 2 Jun 2026 20:26:25 +0200 Subject: [PATCH] feat: support jump host ports in SSH menu Allow jump host definitions to include an explicit port in the form user@host:port. Default to port 22 when no port is provided and update the sample config and docs accordingly. --- .memory/project.md | 1 - README.md | 3 +++ mtm-ssh-menu | 9 ++++++++- sample-config/global.yaml | 2 ++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.memory/project.md b/.memory/project.md index d5042fc..3372cf2 100644 --- a/.memory/project.md +++ b/.memory/project.md @@ -9,6 +9,5 @@ - Documentation language: English. - Current task focus: keep README and memory aligned with the working script and sample configuration. - Known follow-up improvements: - - Jump server currently does not support an alternate port; this needs to be added. - Group naming should avoid duplicating the file name and the YAML value. - Each group should have default values. diff --git a/README.md b/README.md index 1f50f77..a3620f8 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ ssh: default_options: "" jump_hosts: office: "user@192.168.10.11" + office-alt: "user@192.168.10.11:2222" + ``` ### `hosts/dev.yaml` @@ -98,6 +100,7 @@ A complete sample configuration is available in `sample-config/`. ## Notes - `jump_host` values are resolved by name from `global.yaml`. +- Jump hosts support `user@host` and `user@host:port`; if the port is omitted, `22` is used. - If a host does not define a user or port, global defaults are used. - `default_options` is present in the config but not consumed by the current script. - The sample config includes `ssh_options` in one file, but the current script does not consume it yet. diff --git a/mtm-ssh-menu b/mtm-ssh-menu index 1f05a97..bf44cc0 100755 --- a/mtm-ssh-menu +++ b/mtm-ssh-menu @@ -153,7 +153,14 @@ ssh_connect() { SSH_JUMP_HOST=$(jq -r '.jump_host // ""' <<<"$SERVER") if [ "$SSH_JUMP_HOST" != "" ]; then SSH_JUMP_HOST=$(jq -r '.'"$SSH_JUMP_HOST"' // ""' <<<"${SSH_JUMP_HOSTS}") - SSH_JUMP_HOST="-t $SSH_JUMP_HOST ssh -p $SSH_SERVER_PORT" + SSH_JUMP_HOST_USER=$(cut -d'@' -f1 <<<"$SSH_JUMP_HOST") + SSH_JUMP_HOST_TARGET=$(cut -d'@' -f2- <<<"$SSH_JUMP_HOST") + SSH_JUMP_HOST_TARGET_HOST=$(cut -d':' -f1 <<<"$SSH_JUMP_HOST_TARGET") + SSH_JUMP_HOST_TARGET_PORT=$(cut -s -d':' -f2 <<<"$SSH_JUMP_HOST_TARGET") + if [ "$SSH_JUMP_HOST_TARGET_PORT" = "" ]; then + SSH_JUMP_HOST_TARGET_PORT="22" + fi + SSH_JUMP_HOST="-t ${SSH_JUMP_HOST_USER}@${SSH_JUMP_HOST_TARGET_HOST} ssh -p ${SSH_JUMP_HOST_TARGET_PORT}" SSH_SERVER_OPTIONS="" fi diff --git a/sample-config/global.yaml b/sample-config/global.yaml index d026593..6aff23d 100644 --- a/sample-config/global.yaml +++ b/sample-config/global.yaml @@ -4,3 +4,5 @@ ssh: default_options: "" jump_hosts: office: "user@192.168.10.11" + dev: "user@192.168.10.11:2222" + backup: "admin@10.0.0.5:2200"