Fix @unknown Terminal Prompt in MacOS

Some Mac Terminal app users may find that their zsh prompt and Mac host name at the command line randomly sets itself to “@unknown”, or some variation of that. Opening the Terminal, you might find your prompt is something like “@unknown92844982″, @unknown184Afb84.home”, @UNKNOWN, or some variation of “@unknown” with a bunch of alphanumeric characters on the end of it, appended by .home, rather than displaying the computer name as one might expect.
The @unknown.home command prompt quirk has existed spontaneously in many versions of MacOS, and it might even be a bug in Terminal or elsewhere, though there does not always seem to be a clear cause. Given that the hostname prompt gibberish isn’t too informative, and it’s a bit unsightly, let’s get it fixed and have your computer name, or host name of choice, be set instead.
You might have already attempted to use the ‘hostname’ command, but found that it does not persist, even if you use sudo. What you’ll need to do instead is use the scutil command, which allows you to set the hostname, computer name, and bonjour name on the Mac, and that is what will fix the terminal prompt hostname @unknown error.
How to Fix @unknown Terminal Prompt on Mac
- Open the Terminal application if you have not done so already
- From the Terminal, enter the following command string, replacing “MacBook” with the hostname you’d like to set for the Mac:
- Hit return and enter your admin password when requested
sudo scutil --set HostName "MacBook"
Now that you have successfully set the hostname on the Mac, you need to refresh the terminal or open a new terminal window to see the newly defined hostname set properly as your zsh prompt.
When you go to open a new Terminal, you will now see a zsh prompt that is perhaps more like what you’d expect to see, something like “Paul@MacBookPro”. You should no longer see the “@unknown” as the host name as your command prompt, if you do, you likely entered the syntax incorrectly, didn’t use sudo, or need to open a new terminal window.
Again this is not necessarily a new issue, though it does seem to impact people randomly, and users have reported their prompt becoming @unknown for many versions of MacOS system software, from Catalina 10.15 to Golden Gate 27, and probably other versions too. We even first covered setting the username from the Terminal using the scutil command all the way back in 2010, so issues with hostnames not sticking in the Terminal on a Mac is not exactly the most new or unique objection on earth.
Have you ever run into this peculiar quirk or bug in the Terminal? Did you find another resolution to the issue? Let us know your experiences and thoughts.

