What Is the Mac Command Line & Why Is It Important for IT Admins?

5 Ways to Leverage Mac Terminal Commands

Written by Kelsey Kinzer on March 25, 2022

Share This Article

Jump to Commands

As a Mac admin, or an IT admin overseeing a cross-OS fleet, your role revolves around managing your company’s Apple system infrastructure. To carry out your role efficiently, it is helpful to understand how to use the common Unix commands. 

Additionally, while most users of macOS are more familiar with the graphical user interface (GUI), the command line interface (CLI) is more powerful and saves time. In fact, there are some tasks that cannot be accomplished by any other method except the command line.

In this article we will explore the command line, plus its applications and key benefits for IT admins.

What Is the Command Line?

A command line, accessed with Terminal.app, empowers you to work on Macs remotely or locally and control a macOS system through a series of text-based commands and scripts. 

With an admin account, you can make a tweak to almost everything on your Mac via the Terminal.app. You can also leverage the app to securely connect to servers and workstations remotely and to create simple or complex scripts for automating actions.

When a command is successful, the command line does not display any indicator to notify you of the success. Instead, you will get a new line with your username as shown in Figure 1. It’s important to note that the command and arguments you type in Terminal are case sensitive. 

Figure 1

Launching the Terminal.app

To open Terminal on your Mac, you can search “terminal” in Spotlight as shown in Figure 2 or navigate through Applications > Utilities > Terminal. Once you launch the app, a small window with a command prompt will appear; this is the powerful command line (Figure 3).

Figure 2
Figure 3

What Is Possible with Terminal?

You can accomplish many tasks via the CLI, both easy and difficult. From showing hidden files, to getting a list of actively running computer processes, to rebooting a remote workstation, to automating workflows, the number of tasks you can achieve with the terminal app is impressive. 

In this section, we will introduce five common commands that every Mac admin should know, but first, let’s learn how to gain admin level privileges.

How to Get Admin Privileges on macOS

Executing many commands in the command line will require you to have admin level privileges, i.e., you are expected to be a superuser. For instance, if you do not have the correct privileges and you attempt to run the shutdown command, the command line will return an error saying you are not a superuser (as seen in Figure 4).

Figure 4

Therefore, to run commands as a superuser, you need to add the sudo command; sudo stands for superuser do. This can be done in two ways: 

  1. Add sudo to every command you run (as demonstrated in the next part of this article).
  2. Execute a sudo command at the beginning of each terminal session so you don’t have to add sudo to every command you run (refer to Figure 5). 

To gain admin level privileges via the second method, simply run the following command:

sudo -s

Figure 5

Five Helpful Mac Terminal Commands Every IT Admin Should Know

We’ve put together a full tutorial series on the common commands every Mac admin must know. We will briefly discuss the commands here and provide a link to the associated article if you would like to learn more.

1. Enable SSH for Accessing a Remote Mac’s Shell Securely

SSH — also known as Secure Socket Shell or Secure Shell — is a secure network protocol that allows users, especially system admins, to securely access remote devices. To enable SSH, enter and execute the -setremotelogin command as follows:

sudo systemsetup -setremotelogin on

To know if SSH has been successfully enabled, simply run and execute the following:

sudo systemsetup -getremotelogin

Read our full tutorial on how to enable SSH for accessing a remote Mac’s shell securely.

2. Rename Computer Name, Hostname, and Bonjour on macOS

The ability to name each computer in your Mac fleet will allow you to identify and distinguish between them. Using the scutil command, you can rename your computer name, hostname, and local hostname via the Terminal app. 

  • To rename the computer name: sudo scutil –set ComputerName <YourComputerName>
    • Replace <YourComputerName> with the actual name you want to rename your computer
  • To rename hostname: sudo scutil –set HostName YourHostName
  • To rename bonjour name (also known as local hostname): sudo scutil –set LocalHostName YourLocalHostName

Check out the full tutorial on how to rename your computer name, hostname and bonjour name.

3. Bind a Mac to Active Directory 

Active Directory (AD) provides crucial user and device management capabilities as an identity provider for IT systems. However, IT admins find it challenging to manage Macs with Active Directory because AD was originally created to support Windows systems. To bind a Mac to Active Directory, run the following command in the terminal app:

sudo dsconfigad -preferred <adserver.example.com> -a <computername> –domain example.com -u administrator -p <password>

Replace <adserver.example.com>, <computername>, example.com, <username> and <password> with your actual information. 

Learn more in our full tutorial on how to join Mac to Active Directory services.

4. Install macOS Software Updates Remotely

A Mac admin managing multiple workstations can improve efficiency and productivity if they understand how to install software updates remotely. You can invoke the softwareupdate command in the terminal to achieve this goal. The command will cause macOS to install or download some or all software updates depending on your choice of argument (see a partial list below):

  • To install all the updates: sudo softwareupdate -i -a OR  sudo softwareupdate –install –all
  • To install only the updates recommended by Apple: sudo softwareupdate -i -r OR  sudo softwareupdate –install –recommended
  • To install only specific updates: sudo softwareupdate -i <NAME of update exactly as it appears in the list of updates>

We created a comprehensive tutorial on how to install macOS software updates remotely, you can find the full list of argument options there.

5. Logoff, Restart, and Shutdown 

Executing the shutdown command via the terminal app will shutdown, restart, or put your computer in sleep mode depending on the argument used. Below is a list of options:

  • To shut down your computer immediately: sudo shutdown -h now
  • To shut down your computer 10 minutes from now: sudo shutdown -h +10
  • To restart your computer immediately: sudo shutdown -r now
  • To immediately put your computer in sleep mode: sudo shutdown -s now

Read our full tutorial for more details on how to logoff, restart, and shutdown macOS systems.

Key Benefits of Command Line for IT Admins

Clearly, the CLI is an important tool in IT admins’ arsenal. Some of the key benefits of the command line for IT admins include the following:

  1. You can use the command line remotely with greater ease and flexibility than the graphic user interface (GUI).
  2. Once you master it, the command line is faster, more efficient, and more powerful to use.
  3. Leveraging shell scripting, you can automate long and repetitive tasks in the command line. 
  4. The command line requires far less system memory compared to the GUI.

Whether you’re a command line power user or still learning the ropes, did you know you can leverage the JumpCloud Directory Platform to simplify the management of your Mac fleet? From seamless MDM to directory-integrated patch management, our cloud directory platform was designed to consolidate IT tooling and make admins’ lives easier.

Kelsey Kinzer

Kelsey is a passionate storyteller and Content Writer at JumpCloud. She is particularly inspired by the people who drive innovation in B2B tech. When away from her screen, you can find her climbing mountains and (unsuccessfully) trying to quit cold brew coffee.

Continue Learning with our Newsletter