lima-vm/lima · warning

port not found in %#q

Error message

port not found in %#q

What it means

sshPortFromConfig scans the instance's ssh.config line by line for a line starting with 'Port ' and returns its numeric value. If no such line exists, it returns 'port not found in <configPath>'. Callers treat ErrNotExist as benign but this error is surfaced on the instance.

Source

Thrown at pkg/store/instance.go:262

			return 0, err
		}
	}
	return pid, nil
}

// sshPortFromConfig extracts the SSH port from an ssh config file.
func sshPortFromConfig(configPath string) (int, error) {
	b, err := os.ReadFile(configPath)
	if err != nil {
		return 0, err
	}
	for line := range strings.SplitSeq(string(b), "\n") {
		line = strings.TrimSpace(line)
		if port, ok := strings.CutPrefix(line, "Port "); ok {
			return strconv.Atoi(port)
		}
	}
	return 0, fmt.Errorf("port not found in %#q", configPath)
}

type FormatData struct {
	limatype.Instance `yaml:",inline"`

	// Using these host attributes is deprecated; they will be removed in Lima 3.0
	// The values are available from `limactl info` as hostOS, hostArch, limaHome, and identifyFile.
	HostOS       string `json:"HostOS" yaml:"HostOS" lima:"deprecated"`
	HostArch     string `json:"HostArch" yaml:"HostArch" lima:"deprecated"`
	LimaHome     string `json:"LimaHome" yaml:"LimaHome" lima:"deprecated"`
	IdentityFile string `json:"IdentityFile" yaml:"IdentityFile" lima:"deprecated"`
}

var FormatHelp = "\n" +
	"These functions are available to go templates:\n\n" +
	textutil.IndentString(2,
		strings.Join(textutil.FuncHelp, "\n")+"\n")

View on GitHub (pinned to dd909d0973)

Solutions

  1. Add or fix a 'Port <number>' line in ~/.lima/<inst>/ssh.config (single space after 'Port')
  2. Delete ssh.config and restart the instance so Lima rewrites it
  3. Check the actual forwarded port via `limactl list` / hostagent Info and set it manually if needed
  4. Recreate the instance if config regeneration is not possible

Example fix

// before: ssh.config missing port line
Host lima-myvm
  HostName 127.0.0.1
// after
Host lima-myvm
  HostName 127.0.0.1
  Port 49153
Defensive patterns

Strategy: validation

Validate before calling

b, err := os.ReadFile(filepath.Join(instDir, "ssh.config"))
if err == nil && !strings.Contains(string(b), "Port ") {
    // missing Port directive: regenerate or fix ssh.config before Inspect
}

Try / catch

inst, err := store.Inspect(ctx, instDir)
for _, e := range inst.Errors {
    if strings.Contains(e.Error(), "port not found") {
        // regenerate ssh.config by stopping and starting the instance
    }
}

Prevention

When it happens

Trigger: The ssh.config file exists but contains no line with the 'Port ' prefix (note: requires exactly 'Port ' at line start after trimming, not 'Port\t' without space or lowercase 'port').

Common situations: User hand-edited or regenerated ssh.config without a Port directive; port line written with a tab instead of a space; config truncated to only Host/HostName lines after a bad restore.

Related errors


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