Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Change the Computer Name on macOS

In the Apple environment, particularly on macOS, the computer name is a crucial identifier that helps you distinguish your device on a network. Changing the computer name can be useful for organizational purposes, especially in a multi-device setup. This article will guide you through the steps to change the computer name on macOS using both the graphical user interface (GUI) and the command line.


Examples:


Changing the Computer Name via System Preferences (GUI)


1. Click on the Apple menu in the top-left corner of your screen and select "System Preferences."
2. In the System Preferences window, click on "Sharing."
3. In the Sharing preferences pane, you will see a field labeled "Computer Name." Click on this field and enter your desired computer name.
4. Close the System Preferences window. Your computer name is now updated.


Changing the Computer Name via Terminal (Command Line)


1. Open the Terminal application. You can find it in the Applications > Utilities folder or by searching for "Terminal" using Spotlight.
2. To change the computer name, use the following command:


   sudo scutil --set ComputerName "NewComputerName"

Replace "NewComputerName" with your desired computer name. You will be prompted to enter your administrator password.


3. To change the local hostname (the name used by Bonjour and other network services), use the following command:


   sudo scutil --set LocalHostName "NewLocalHostName"

Replace "NewLocalHostName" with your desired local hostname.


4. To change the hostname (the name used by the Terminal and other command-line utilities), use the following command:


   sudo scutil --set HostName "NewHostName"

Replace "NewHostName" with your desired hostname.


5. Verify the changes by running:


   scutil --get ComputerName
scutil --get LocalHostName
scutil --get HostName

Example Script to Automate the Process


If you frequently need to change the computer name on multiple devices, you can use a shell script to automate the process:


#!/bin/bash

# Define the new names
NEW_COMPUTER_NAME="NewComputerName"
NEW_LOCAL_HOST_NAME="NewLocalHostName"
NEW_HOST_NAME="NewHostName"

# Change the computer name
sudo scutil --set ComputerName "$NEW_COMPUTER_NAME"
sudo scutil --set LocalHostName "$NEW_LOCAL_HOST_NAME"
sudo scutil --set HostName "$NEW_HOST_NAME"

# Verify the changes
echo "Computer Name: $(scutil --get ComputerName)"
echo "Local Hostname: $(scutil --get LocalHostName)"
echo "Hostname: $(scutil --get HostName)"

Save this script as change_name.sh, make it executable with chmod +x change_name.sh, and run it with sudo ./change_name.sh.


To share Download PDF