Renaming a Mac looks like a one-field job, and for most people it is — two panes in System Settings cover it. The trouble starts when the old name keeps turning up afterwards: in the Terminal prompt, in a network share, in an SSH session. That is not a caching bug. A Mac carries three separate names, the graphical settings reach two of them, and the third is left unset. This page starts with the point-and-click version, then explains why the leftovers happen and how to deal with them.
Rename your Mac in System Settings
This is the name other people see — in AirDrop, in the Finder sidebar when they browse the network, on a shared printer. Changing it takes four steps:
- Open System Settings from the Apple menu or the Dock.
- Click General > About in the sidebar.
- Click the Name field at the top and type the new name.
- Press Return or click elsewhere. There is no Save button and no confirmation — the change is written as you leave the field.
If the sidebar looks different on your version of macOS, use the search field at the top of System Settings and type computer name. The pane is indexed under “computer, name, pc, host, hostname, local”, so any of those words finds it.
Two things can stop you here. If the field is greyed out and you see “The name of this computer is set by your system administrator and cannot be changed”, the Mac is centrally managed — that is a policy on a work machine, not something to work around locally. And if you get “A computer with the name … is in use by another user. Change your computer name or try again later”, another device on the same network already answers to it, so pick something else.
Change the network name too
The name above is the friendly one. There is a second, stricter name used for network addressing, and it lives in a different pane:
- In System Settings, go to General > Sharing.
- Computer Name sits at the top, showing the same value you just set.
- Click Edit… to reveal Local hostname, described in the sheet as the address at which “Computers on your local network can access your computer”.
- Type the value you want and click Done.
This field will not accept just anything, and the sheet states the rule up front: “The Bonjour Name must start and end with a letter or digit. The interior characters must consist of only letters, digits, and hyphens.” No spaces, no apostrophes, no emoji. Skip this step and macOS fills the field in for you by mangling the friendly name until it fits — which is the subject of the next section.
Notice the line macOS prints under the name: “Others can access your computer locally at [name].local or globally at [name].” That .local address is what ends up in your Terminal prompt — the first hint that these names are chained together.
For most people that is the whole job. If the old name still appears somewhere after both changes, keep reading — there is a third name, and no pane in System Settings touches it.
Why a Mac has three names
scutil reads all three at once, and seeing them together is what makes the behaviour obvious:
$ scutil --get ComputerName
osxhub's Mac (2)
$ scutil --get LocalHostName
osxhubs-Mac-2
$ scutil --get HostName
HostName: not set
The two name values above are replaced with a placeholder; the relationship between them and the third line are exactly as this machine reports them. What each one is for, in man scutil‘s own words:
ComputerName The user-friendly name for the system.
LocalHostName The local (Bonjour) host name.
HostName The name associated with hostname(1) and
gethostname(3).
The first two are the fields you just edited. HostName is the Unix hostname, no pane in System Settings exposes it, and on a stock machine it does not exist at all. That third line is the result, not a helpful notice about a missing value, and the exit status confirms it: scutil --get HostName returns 1 when the preference is unset and 0 when it is set — which is what a script should branch on rather than matching the text.
Now compare the first two values. When you leave the Local hostname alone, macOS derives it from the friendly name by stripping everything a hostname cannot contain:
- The apostrophe in
osxhub'sdisappears entirely — it becomesosxhubs. - Whitespace collapses to a single hyphen, even where there were two spaces.
- The parentheses around
(2)are dropped and the digit is kept, joined with a hyphen.
That is why the two names drift apart and why the derived one looks mangled. Setting Local hostname yourself in the Sharing pane is what stops the guessing.
Why hostname returns a name you never set
Here is the part that confuses people coming from Linux. HostName is unset, and yet:
$ hostname
osxhubs-Mac-2.local
$ hostname -s
osxhubs-Mac-2
With no HostName configured, the system falls back to the Bonjour name with .local appended — the same address the Sharing pane showed you. So the name in your shell prompt, in ssh banners, and in anything calling gethostname() is a byproduct of what you typed into the Name field, two derivations removed.
The Linux habit that does not transfer: hostnamectl does not exist on macOS, and hostname newname is the wrong tool even though it appears to work. man hostname spells out why in two sentences: “The super-user can set the hostname by supplying an argument. To keep the hostname between reboots, run ‘scutil –set HostName name-of-host’.” A bare hostname assignment does not survive a restart, because it never touches the preference that gets read at boot.
Setting all three from the Terminal
--set is the counterpart to --get, and the man page is explicit about one requirement: “The –set option requires super-user access.” Three commands cover what the two panes above do, plus the one they cannot reach:
sudo scutil --set ComputerName "Studio Mac"
sudo scutil --set LocalHostName "studio-mac"
sudo scutil --set HostName "studio-mac"
Set them in that order. ComputerName first, because writing it can regenerate LocalHostName and overwrite a value you set beforehand; LocalHostName second, so you get the exact Bonjour name you want rather than the derived one; HostName last, since nothing derives from it.
Only ComputerName gets the readable version with spaces; LocalHostName has to satisfy the Bonjour rule quoted earlier, and HostName is conventionally the same, or a fully qualified name like studio-mac.example.com if the machine really has one in DNS. Setting HostName is the step both the graphical panes and most guides skip, and it is the one that stops .local from appearing in your prompt.
Where the old name keeps showing up
If a name persists after a change, work down this list before assuming something is broken.
- Your current Terminal session. The prompt is expanded when the shell starts. Open a new tab; the old one keeps the old name until it exits.
- You only changed one of the three. Run all three
--getcommands. This accounts for most of the “it did not work” reports — the name you looked at afterwards was not the name you set. - Other devices on the network. Bonjour records are cached by the machines that saw the old name, not by yours. They expire on their own.
- A trailing number appeared that you never typed. If the friendly name has no digit in it but the Local hostname ends in
-2, the Bonjour name was already claimed on that network and macOS took the next free one. Rename the other machine, or set Local hostname explicitly.
That last one explains a lot of Macs quietly answering to something-2. The suffix lands on the network name only, so the Name field still reads clean while every .local lookup uses the numbered version — exactly the mismatch that sends people hunting for a cache to clear.
Quick reference
| Name | Where to change it | Where it shows up |
|---|---|---|
| ComputerName | General > About > Name, or scutil --set ComputerName | AirDrop, Finder sidebar, Sharing pane |
| LocalHostName | General > Sharing > Edit…, or scutil --set LocalHostName | Bonjour, .local addresses, screen sharing |
| HostName | sudo scutil --set HostName only | hostname, shell prompt, SSH; unset by default |
| All three | scutil --get <name> to read | Set ComputerName first, HostName last |
If you only remember one thing: run the three --get commands before and after any rename. Almost every strange leftover on a Mac’s name resolves into “the three values disagree”, and seeing them together tells you which one still needs setting.

