Change MacOS machine name from command line
One of the first things I do when I get a new Mac is to change the machine name. I hate the default name that Apple gives to the machine, so I always change it.
There are many ways to do that, but for me I like to go to the command line and use the scutil
command.
sudo scutil --set ComputerName "machine-name"
sudo scutil --set HostName "machine-name"
sudo scutil --set LocalHostName "machine-name"
after that you chan check the name with the following command:
scutil --get ComputerName
Note that I setting the ComputerName
, HostName
, and LocalHostName
to the same value.
This is not strictly necessary, but I like to keep things consistent.
This gives:
ComputerName: Visible in Finder and AirDrop.
HostName: Used by SSH and CLI tools as machine-name
.
LocalHostName: Resolves as machine-name.local
via Bonjour/mDNS.
Thats all, be creative when choosing your machine name!
Thank you