Skip to content

feat: resolve SSH usernames and report authentication failures #62

Closed

Description

@abruption

Context

Related roadmap: #45. Split from the return-route review in #61 because SSH account resolution and transport failure classification are independent of Codex home activity.

Host identity does not determine an OS login account:

  1. An entry in known_hosts records a host key, not a username.
  2. Tailscale peer and MagicDNS records identify a device, not the remote SSH account.
  3. Without USER@HOST or an SSH User setting, OpenSSH falls back to the caller's local username, which may not exist on the destination.
  4. A wrong username currently produces an opaque SSH failure, and callers cannot tell which account was attempted or whether changing the host, key, or username is appropriate.

Proposed behavior

  • Preserve the requested SSH alias so its ~/.ssh/config Host and User settings continue to apply while verified MagicDNS routing overrides only HostName.
  • Resolve the effective attempted username with ssh -G using the same destination and safe SSH options used for the connection.
  • Apply precedence: explicit USER@HOST, then effective OpenSSH configuration/default. Do not infer a username from known_hosts, Tailscale identity, MagicDNS, or usernames observed on other machines.
  • Report an explicit user as sshUserSource: "explicit". When no explicit user was supplied, report sshUserSource: "ssh_config_or_local_default"; do not pretend to know whether OpenSSH obtained it from config or its default without parsing private configuration.
  • Classify failed SSH attempts at least as authentication_failed, host_key_failed, timeout, or transport_failed. Include the effective sshUser when known.
  • Authentication failure must be terminal for that request. Never retry guessed usernames or cycle through local accounts.
  • Give an actionable remedy: use --host USER@HOST or set User for the original alias in ~/.ssh/config.

Example failure:

{
  "ok": false,
  "host": "macbook-pro-m4-pro.tailnet.ts.net",
  "sshUser": "ubuntu",
  "sshUserSource": "ssh_config_or_local_default",
  "sshFailure": "authentication_failed",
  "error": "SSH authentication failed for [email protected]; use --host USER@HOST or configure SSH User"
}

Acceptance criteria

  • USER@HOST takes precedence and is reported as explicit.
  • An SSH-configured User is honored through the original alias and exposed as the effective attempted user.
  • A host known only through known_hosts or Tailscale does not invent a remote username beyond OpenSSH's documented local-user default.
  • Authentication, host-key, timeout, and other transport failures have distinct structured results locally and in multi-host JSON.
  • Wrong usernames are never automatically retried.
  • Existing safe SSH option validation, MagicDNS verification, host attribution, and multi-host continuation remain intact.
  • Tests cover explicit users, SSH-config/default users, missing ssh -G, malformed output, each failure class, and usernames/hosts requiring safe argument handling.
  • README/help explain username precedence and both supported configuration forms.

Related: #29, #45, #57, #61.

Activity

  1. added
    enhancement
    on Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions