abiosoft/colima · error

error reading ssh config: %w

Error message

error reading ssh config: %w

What it means

Returned by generateSSHConfig (app/app.go:701) when os.Stat on ~/.ssh/config succeeded but the subsequent os.ReadFile failed. Colima reads the existing SSH config to scan for an Include line before prepending one for its generated ssh_config, so an unreadable file blocks the scan.

Source

Thrown at app/app.go:701

	sshFileSystem := filepath.Join(util.HomeDir(), ".ssh", "config")

	// include the SSH config file if not included
	// if ssh file missing, the only content will be the include
	if _, err := os.Stat(sshFileSystem); err != nil {
		if err := os.MkdirAll(filepath.Dir(sshFileSystem), 0700); err != nil {
			return fmt.Errorf("error creating ssh directory: %w", err)
		}

		if err := os.WriteFile(sshFileSystem, []byte(includeLine), 0644); err != nil {
			return fmt.Errorf("error modifying %s: %w", sshFileSystem, err)
		}

		return nil
	}

	sshContent, err := os.ReadFile(sshFileSystem)
	if err != nil {
		return fmt.Errorf("error reading ssh config: %w", err)
	}

	scanner := bufio.NewScanner(bytes.NewReader(sshContent))
	for scanner.Scan() {
		words := strings.Fields(scanner.Text())

		// empty line
		if len(words) == 0 {
			continue
		}

		// comment
		if strings.HasPrefix(words[0], "#") {
			continue
		}

		// not an include line
		if len(words) < 2 {

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Inspect ownership and ACLs: `ls -le ~/.ssh/config`, then fix: `sudo chown $(id -un):$(id -gn) ~/.ssh/config`
  2. Ensure read permission: `chmod u+r ~/.ssh/config`
  3. If the file must stay protected from colima, skip modification: `colima start --modify-ssh-config=false` and add the Include line manually
  4. Re-run `colima start` after fixing to confirm the read succeeds

Example fix

# before
ls -le ~/.ssh/config   # e.g. -rw-r--r--  1 root  staff  ... => read fails

# after
sudo chown $(id -un):$(id -gn) ~/.ssh/config
chmod u+rw ~/.ssh/config
colima start
Defensive patterns

Strategy: validation

Validate before calling

// Probe readability of ~/.ssh/config before triggering colima's modification
sshCfg := filepath.Join(home, ".ssh", "config")
if _, err := os.Stat(sshCfg); err == nil {
    if f, err := os.Open(sshCfg); err != nil {
        return fmt.Errorf("~/.ssh/config unreadable; fix ownership/mode or run colima with --modify-ssh-config=false")
    } else {
        _ = f.Close()
    }
}

Try / catch

if err := runColimaStart(); err != nil {
    if strings.Contains(err.Error(), "error reading ssh config") {
        // filesystem permission problem on ~/.ssh/config:
        // chown/chmod the file, or bypass with colima start --modify-ssh-config=false
    }
    return err
}

Prevention

When it happens

Trigger: stat succeeds but read fails: permission denied (file owned by root or another user, restrictive ACLs), the file being replaced between stat and read (race), or unusual filesystems/endpoint-security software blocking the read.

Common situations: ~/.ssh/config created or chowned by sudo/restore/migration tools leaving root ownership; corporate DLP blocking reads of SSH files; running colima as a different user than the one owning ~/.ssh.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/c27f9910bf70c79e. Report an issue: GitHub.