How to find the Computer Hostname and Username

If you need to find your computer's host name or the username, for example, during troubleshooting or when instructed to do so by a Teramind Support Agent, here are some commands you can use.

Windows

From your Windows Start Menu or from the Windows Search Bar, type cmd.exe and press Enter.

When the Command Prompt opens, type the following command(s) and press Enter:

whoami

- this will return the computer name and the username. For example, desktop-30lv124\john-work.

whomai /upn

- this will return the User Principal Name (UPN). An UPN in Windows Active Directory is the name of a system user that consists of the user name (logon name) and the domain name (UPN suffix). For example: john.smith@mydomain.com. Note that while the UPN looks like an email address it is not one.

echo %username%

- will show the display name in case the account is named differently than the user profile account. For example, John Work.

macOS

Click the Launchpad icon in the Dock, type Terminal in the search field, then click Terminal.

Or, in the Finder , open the /Applications/Utilities folder, then double-click Terminal.

Type the following command(s) from the Terminal prompt and press Enter:

whoami

- similar to Windows' equivalent command (see above).

hostname

- this will return the computer's host name such as john-macbook-pro.

scutil --get HostName

- returns results similar to the hostname command above.

scutil --get LocalHostName

- this will return the computer host name such as john-macbook-pro.local.  A local host name designates a computer on a local subnet. This is mostly used for Bonjour-aware services on the local network.

scutil --get ComputerName

- will return the computer's name. For example, John's MacBook Pro.

Was this article helpful?
2 out of 4 found this helpful