kopia/kopia · error

can't get password

Error message

can't get password

What it means

askPass reads the repository password interactively from a terminal (or from stdin when supported). If every read attempt fails or yields nothing (EOF, no TTY, read error), it gives up and returns the generic error "can't get password".

Solutions

  1. Pass the password explicitly: --password or the KOPASSWORD environment variable
  2. Ensure stdin is an open interactive TTY (avoid `kopia ... < /dev/null`)
  3. Use --use-.saved-credentials or kopia's credentials file for scripted runs
  4. Check terminal emulation/SSH pty allocation when running remotely

Example fix

// before (script, no TTY)
kopia repository connect s3 ...
// after
KOPASSWORD=secret kopia repository connect s3 ...
Defensive patterns

Strategy: fallback

Validate before calling

// ensure a TTY or explicit password source before invoking
if password == "" && os.Getenv("KOPASSWORD") == "" && !term.IsTerminal(int(os.Stdin.Fd())) {
    return errors.New("no interactive terminal and no KOPASSWORD set")
}

Try / catch

out, err := askPass(...)
if err != nil {
    if strings.Contains(err.Error(), "can't get password") {
        // fall back to KOPASSWORD or --password
    }
}

Prevention

When it happens

Trigger: Running kopia non-interactively without KOPASSWORD/--password and stdin unavailable or closed; terminal read failing after retries in askPass.

Common situations: CI jobs and cron/scripts without a TTY, piped empty stdin, kopia prompts consumed by other tooling, or entering empty input twice.

Related errors


AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07). Data as JSON: /api/errors/13439c023896b312. Report an issue: GitHub.

Appendix: source

Thrown at cli/password.go:120

	for range 5 {
		fmt.Fprint(out, prompt) //nolint:errcheck

		passBytes, err := term.ReadPassword(fd)
		if err != nil {
			return "", errors.Wrap(err, "password prompt error")
		}

		fmt.Fprintln(out) //nolint:errcheck

		if len(passBytes) == 0 {
			continue
		}

		return string(passBytes), nil
	}

	return "", errors.New("can't get password")
}

var errFdConversionOverflows = errors.New("uintptr file descriptor conversion to int overflows")

func intFd(f *os.File) (int, error) {
	fd := f.Fd()

	if fd <= math.MaxInt {
		return int(fd), nil
	}

	return -1, errFdConversionOverflows
}

View on GitHub (pinned to 82495e54b5)