This article continues our series on the common commands every Mac admin should know. Check out the previous articles in this series to learn how to:
- Enable SSH to access a remote Mac’s shell securely
- Change your device name, hostname and local hostname
- Bind a Mac to Active Directory
The major responsibilities of Mac sysadmins include managing, troubleshooting, maintaining, and updating macOS. Sometimes, the GUI becomes unresponsive. In these cases, it is critical for IT admins to understand how to logoff, restart, and shutdown the systems remotely, via the terminal. This tutorial presents the commands that can be executed in the command line to logoff, restart, or shutdown macOS systems.
Difference Between Logoff, Restart, and Shutdown on macOS
Before we dive into executing these commands via the terminal, it’s important to get acquainted with the difference between the actions.
Logging off simply means you log out of the user profile; the Mac will show the login screen where the user will need to log in before they can use the system again.
Restarting means to reboot the device so that it starts afresh. If you restart a device, it will close all the active applications on the device and go through the startup process automatically.
Putting the device in sleep mode will initiate a screensaver to conserve energy. Wiggling the mouse or tapping the space bar will wake it up again. Depending on the settings, it may or may not require the user to enter their password upon waking. The device is immediately ready for the user to work on all the apps and programs that were running before putting it in sleep mode.
Finally, just as the name implies, shutting down a MacBook means that you shut down the entire macOS system. All active applications will close once the device turns off. If the user hasn’t quit each app before shutting down the device, the apps will reopen automatically, allowing the user to get back to work more quickly.
Logging Off, Restarting, or Shutting Down macOS Systems via the Terminal App
In this section, we will go through how you can execute a command in the terminal app to restart, shutdown, logoff, or put your device in sleep mode. To get started, you need to launch the terminal app. Simply search “terminal” using the Spotlight search option on your device or navigate through Applications > Utilities > Terminal.
1. Shutting Down a macOS System
Here, we will use the
shutdown command. All you need to do to shutdown your device with immediate effect is to run the following command (Figure 1):
sudo shutdown -h now
sudo to the command to gain admin-level privileges. When you run the command, you will have to provide your admin password. The
-h argument will halt all processes immediately. Executing the command with no arguments will shut down your macOS after a minute. Either way, using the terminal to shut down the device will make it inaccessible.
If you want to schedule the device to shut down at a specific time, you can define that with the command below. The “hh” in
hhmm represents hours (in 24-hour time) while “mm” represents minutes of the time.
sudo shutdown -h hhmm
For instance, if you want to shutdown the device at 10:19 p.m., you should run the following command (Figure 2):
sudo shutdown -h 2219
Alternatively, you can schedule your device to shutdown at a particular time by defining minutes alone. For example, if you want your macOS to shut down exactly 30 minutes from now, simply run the following command (Figure 3):
sudo shutdown -h +30
2. Restarting a macOS System
To restart your macOS system via the terminal app, we will also leverage the
shutdown command. Run the following command (refer to Figure 4):
sudo shutdown -r now
-r argument tells the system to restart. Executing the
now argument will restart your macOS immediately. However, you can schedule your device to restart after a specific period of time. For example, if you want your device to restart in one hour, you should run the following command (Figure 5):
sudo shutdown -r +60
Note that the
+60 represents 60 minutes (one hour) from the present time.
3. Putting a macOS in Sleep Mode
You can also use the shutdown command to put your macOS in sleep mode. All that is required is to run the following command (Figure 6):
sudo shutdown -s now
You can schedule the device to sleep at a specific period. For instance, if you want your device to go to sleep mode 10 minutes from now, you should run the following (Figure 7):
sudo shutdown -s +10
4. Logging Off a macOS System
Run the following command to logoff of your MacBook (Figure 8):
sudo pkill loginwindow
In this article, we discussed important commands you should understand as you continue to manage macOS systems within your fleet. You are now acquainted with how to logoff, restart, shutdown, or put a macOS device into sleep mode via the terminal app.
Note that you can also leverage the JumpCloud Directory Platform to manage your entire Mac fleet. The streamlined MDM tool enables IT admins to lock, restart, shut down, or even erase any of the remote or on-prem Mac systems in their fleet with the click of a button.
In addition to managing macOS devices, IT admins can also manage Windows and Linux devices as well as identities, access, and other IT resources from one central location in the cloud. You can try it out for free today and manage up to 10 users and 10 devices, no credit card required. You will also enjoy 10 days of 24/7 premium in-app chat support to help you get set up. Sign up for JumpCloud Free today to get started.