Skip to content

SSH Host aliases use raw OS hostnames: spaces split into multiple patterns and duplicates collide #32

Closed

Description

@TMHSDigital

Why it matters

The generated Host aliases often don't work as SSH aliases, and collisions send ssh <name> to the wrong machine without any warning.

Evidence

src/sshconfig.ts:24-27 uses node.hostname.toLowerCase() (the raw OS hostname from tailscale status) as the Host pattern:

renderHostBlocks([{hostname:"My MacBook Pro"}, {hostname:"box"}, {hostname:"box"}])
=> "Host my macbook pro\n ...\n\nHost box\n ...\n\nHost box\n ..."
  • Spaces: Host my macbook pro declares three separate patterns (my, macbook, pro), so ssh pro matches this node. Raw hostnames on macOS and Windows often contain spaces, apostrophes, or Unicode.
  • Duplicates: two peers with the same OS hostname (common for cloned VMs, localhost, or raspberrypi) produce two identical Host blocks. SSH uses the first match, so the second node can't be reached by name. Tailscale already de-duplicates these in MagicDNS (raspberrypi-1), but the server ignores that.
  • Non-SSH peers: Mullvad exit nodes, nodes shared in from other tailnets, and nodes tagged as services all get Host blocks. That adds noise and invites a mistaken ssh to a third-party machine.

Suggested approach

  • Use the first label of dnsName (unique within the tailnet and already DNS-safe) as the alias, and fall back to a sanitized hostname ([a-z0-9-] only).
  • Detect collisions and disambiguate them, or report them in the response.
  • Skip Mullvad and shared-in nodes by default, and add an includeShared/tags filter.
  • Optionally emit HostKeyAlias so key pinning survives IP changes.

Done when

Every generated Host line is a single SSH-safe token that is unique in the block. Tests cover spaces, duplicates, Unicode, and Mullvad/shared peers.

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

    bugpriority: P2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions