Change computer name displayed in Terminal (Mac)

The macOS hostname is split across three scutil keys, and the one that drives your shell prompt isn't the only one you usually want to set:

  • HostName — the network hostname shown in your shell prompt
  • ComputerName — what System Settings → General → Sharing and Finder show
  • LocalHostName — the Bonjour .local name used by AirDrop and LAN SSH

Set all three at once so they don't drift:

1sudo scutil --set ComputerName "mbp-andreas" 2sudo scutil --set LocalHostName "mbp-andreas" 3sudo scutil --set HostName "mbp-andreas" 4dscacheutil -flushcache

LocalHostName only accepts letters, digits, and hyphens — no spaces or punctuation.

Already-open shells keep the old prompt until you exec $SHELL or open a new tab. No reboot needed.

Confirm with:

1scutil --get HostName