lima-vm/lima · warning

failed to extract SSH local port from %#q: %w

Error message

failed to extract SSH local port from %#q: %w

What it means

When the instance's SSHLocalPort is unknown (0), Inspect falls back to parsing the per-instance ssh config file (<instDir>/ssh.config) with sshPortFromConfig. If parsing fails for a reason other than the file not existing, the error is recorded on the instance without marking it broken.

Source

Thrown at pkg/store/instance.go:95

		} else {
			ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
			defer cancel()
			info, err := haClient.Info(ctx)
			if err != nil {
				inst.Status = limatype.StatusBroken
				inst.Errors = append(inst.Errors, fmt.Errorf("failed to get Info from %#q: %w", haSock, err))
			} else {
				inst.SSHLocalPort = info.SSHLocalPort
				inst.AutoStartedIdentifier = info.AutoStartedIdentifier
			}
		}
	}
	if inst.SSHLocalPort == 0 {
		sshConfigPath := filepath.Join(instDir, filenames.SSHConfig)
		if port, err := sshPortFromConfig(sshConfigPath); err == nil {
			inst.SSHLocalPort = port
		} else if !errors.Is(err, os.ErrNotExist) {
			inst.Errors = append(inst.Errors, fmt.Errorf("failed to extract SSH local port from %#q: %w", sshConfigPath, err))
		}
	}

	inst.CPUs = *y.CPUs
	memory, err := units.RAMInBytes(*y.Memory)
	if err == nil {
		inst.Memory = memory
	}
	disk, err := units.RAMInBytes(*y.Disk)
	if err == nil {
		inst.Disk = disk
	}
	inst.AdditionalDisks = y.AdditionalDisks
	inst.Networks = y.Networks

	// 0 out values since not configurable on WSL2
	if inst.VMType == limatype.WSL2 {
		inst.Memory = 0

View on GitHub (pinned to dd909d0973)

Solutions

  1. Check ~/.lima/<inst>/ssh.config content and ensure it has a valid line 'Port <number>'
  2. Fix file permissions (should be readable by the current user)
  3. Delete the instance's ssh.config and restart the instance so Lima regenerates it
  4. As a last resort re-create the instance from its template

Example fix

// before: hand-edited ssh.config
Port abc
// after
Port 49153
Defensive patterns

Strategy: validation

Validate before calling

data, err := os.ReadFile(filepath.Join(instDir, "ssh.config"))
if err == nil && !regexp.MustCompile(`(?m)^Port \d+$`).Match(data) {
    // config lacks a valid Port line; fix before Inspect
}

Try / catch

inst, err := store.Inspect(ctx, instDir)
if inst != nil {
    for _, e := range inst.Errors {
        if strings.Contains(e.Error(), "failed to extract SSH local port") {
            // fall back to stored ssh port or prompt user to restart
        }
    }
}

Prevention

When it happens

Trigger: sshPortFromConfig returns a non-ErrNotExist error while parsing <instDir>/ssh.config: unreadable file (permissions), malformed content causing strconv.Atoi failure after a 'Port ' prefix (e.g. 'Port abc').

Common situations: User hand-edited ~/.lima/<inst>/ssh.config and typoed the port; partial instance directory restored from backup with truncated config; permission issues after copying instance dirs between users.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/300812b018f1c017. Report an issue: GitHub.