kovidgoyal/kitty · error · ValueError

Incorrect password

Error message

Incorrect password

What it means

Inside get_ssh_data(), after reading the password blob from shared memory, the 'pw' field of the request is compared against env_data['pw'] recorded by kitty. A mismatch raises ValueError('Incorrect password'). The exception is caught, its traceback printed, and a sanitized message is yielded to the requesting process, which typically makes the ssh kitten wrapper fail/close the connection.

Source

Thrown at kittens/ssh/utils.py:195

    # Unfortunately we cannot use EOF (\x04) to flush the kernel line buffer
    # because ssh with controlmasters mangles EOF replacing it with null bytes
    from base64 import standard_b64decode

    yield b'\nKITTY_DATA_START\n'  # to discard leading data
    try:
        msg = standard_b64decode(msgb).decode('utf-8')
        md = dict(x.split('=', 1) for x in msg.split(':'))
        pw = md['pw']
        pwfilename = md['pwfile']
        rq_id = md['id']
    except Exception:
        traceback.print_exc()
        yield b'invalid ssh data request message\n'
    else:
        try:
            env_data = read_data_from_shared_memory(pwfilename)
            if pw != env_data['pw']:
                raise ValueError('Incorrect password')
            if rq_id != request_id:
                raise ValueError(f'Incorrect request id: {rq_id!r} expecting the KITTY_PID-KITTY_WINDOW_ID for the current kitty window')
        except Exception as e:
            traceback.print_exc()
            import re

            msg = re.sub(r'[^a-zA-Z0-9 ]+', '_', str(e))
            yield f'{msg}\n'.encode()
        else:
            yield b'OK\n'
            encoded_data = memoryview(env_data['tarfile'].encode('ascii'))
            # macOS has a 255 byte limit on its input queue as per man stty.
            # Not clear if that applies to canonical mode input as well, but
            # better to be safe.
            line_sz = 254
            while encoded_data:
                yield encoded_data[:line_sz]
                yield b'\n'

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Close and retry the ssh kitten session in a single, currently-running kitty instance (stale state is the usual cause).
  2. Quit other kitty instances that may be reusing the same shm names, then retry.
  3. If it's reproducible, check for a kitty bug: report with the printed traceback and kitty --version.
  4. If writing your own client for the ssh kitten IPC, make sure you echo the exact pw sent in the request that created the pwfile.

Example fix

// not a code-level error; remediation is environmental
close stale ssh kitten sessions; retry `kitten ssh host` in the live kitty window
Defensive patterns

Strategy: retry

Try / catch

# server side (get_ssh_data already does this):
try:
    env_data = read_data_from_shared_memory(pwfilename)
    if pw != env_data['pw']:
        raise ValueError('Incorrect password')
except Exception as e:
    traceback.print_exc()
    yield re.sub(r'[^a-zA-Z0-9 ]+', '_', str(e)).encode() + b'\n'

Prevention

When it happens

Trigger: handle_remote_ssh() issues a data request whose pw value doesn't match what kitty stored in the shm pwfile: e.g. a request replayed from a previous session after the shm was recreated, a forged/handcrafted request message, or concurrent kitty sessions mixing up pwfiles. The message format is parsed (msgb) and pw/rq_id extracted before the comparison.

Common situations: Two kitty instances or windows racing over the same shm name; leftover state after kitty crashes/restarts while an ssh kitten session is mid-handshake; scripts trying to mimic the ssh kitten IPC protocol manually; memory corruption or truncated request buffers.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/67badf277af4e236. Report an issue: GitHub.