Skip to content

store.Inspect: fall back to ssh.config for SSH port#4592

Merged
AkihiroSuda merged 1 commit intolima-vm:masterfrom
jandubois:ssh-port-from-config
Feb 16, 2026
Merged

store.Inspect: fall back to ssh.config for SSH port#4592
AkihiroSuda merged 1 commit intolima-vm:masterfrom
jandubois:ssh-port-from-config

Conversation

@jandubois
Copy link
Member

When the host agent is unavailable, the SSH local port remains 0 because Inspect can only retrieve it from the host agent. Extract the port from the instance's ssh.config file as a fallback; this file persists after the host agent dies and contains the port assigned at startup.

Fixes #4583

cd ~/.lima/alpine-isol shell alpine-iso uname -a
Linux lima-alpine-iso 6.12.51-0-virt #1-Alpine SMP PREEMPT_DYNAMIC 2025-10-07 15:12:03 aarch64 Linuxrm ha.sockl shell alpine-iso uname -a
ERRO[0000] Instance "alpine-iso" has configuration errors  error="failed to connect to \"/Users/jan/.lima/alpine-iso/ha.sock\": stat /Users/jan/.lima/alpine-iso/ha.sock: no such file or directory"
Linux lima-alpine-iso 6.12.51-0-virt #1-Alpine SMP PREEMPT_DYNAMIC 2025-10-07 15:12:03 aarch64 Linuxecho "Hello world" >ssh.configl shell alpine-iso uname -a
ERRO[0000] Instance "alpine-iso" has configuration errors  error="failed to connect to \"/Users/jan/.lima/alpine-iso/ha.sock\": stat /Users/jan/.lima/alpine-iso/ha.sock: no such file or directory\nfailed to extract SSH local port from \"/Users/jan/.lima/alpine-iso/ssh.config\": port not found in \"/Users/jan/.lima/alpine-iso/ssh.config\""
Bad port '0'

@jandubois jandubois added this to the v2.1.0 milestone Feb 16, 2026
@jandubois jandubois marked this pull request as draft February 16, 2026 04:33
@jandubois jandubois force-pushed the ssh-port-from-config branch from 0643cb4 to 8bcfe35 Compare February 16, 2026 04:42
When the host agent is unavailable, the SSH local port remains 0
because Inspect can only retrieve it from the host agent. Extract
the port from the instance's ssh.config file as a fallback; this
file persists after the host agent dies and contains the port
assigned at startup.

Fixes lima-vm#4583

Signed-off-by: Jan Dubois <jan.dubois@suse.com>
@jandubois jandubois force-pushed the ssh-port-from-config branch from 8bcfe35 to c1cdcb8 Compare February 16, 2026 04:48
@jandubois jandubois marked this pull request as ready for review February 16, 2026 06:40
}

// sshPortFromConfig extracts the SSH port from an ssh config file.
func sshPortFromConfig(configPath string) (int, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This function is not robust to cover a config with multiple host entries, but we do not need to care about it for Lima-generated config files, at least with the current version)

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit d7a96eb into lima-vm:master Feb 16, 2026
63 of 64 checks passed
}

// sshPortFromConfig extracts the SSH port from an ssh config file.
func sshPortFromConfig(configPath string) (int, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This could be easier for unit testing

Suggested change
func sshPortFromConfig(configPath string) (int, error) {
func sshPortFromConfig(config []byte) (int, error) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract ssh port from ssh.config

2 participants