This guide will explain how to shut down or reboot your Mac using the command line. This can be useful if you are controlling a remote machine via SSH, if you are in single-user mode, or if you are having problems within macOS and need to bypass the GUI.
WARNING If you are using your Mac remotely and you have FileVault switched on, ensure that you run the following command before restarting:
sudo fdesetup authrestart -1
This is necessary because FileVault requires that you unlock your Mac with your password before macOS loads at all — which, obviously, is impossible for a remote user to do. By running
sudo fdesetup authrestart, this feature is disabled on a one-time basis.
Shut down your Mac using the command line
To shut a Mac down instantly, run:
sudo shutdown -h now
To shut a Mac down after a specific number of minutes, run (replacing
+ and then a number):
sudo shutdown -h SECONDS
So, if you want a Mac to shut down after 15 minutes, you’d run:
sudo shutdown -h +15
Restart your Mac using the command line
This process is almost identical to the shutdown process, but we replace
-r in the string. So, to immediately restart the Mac, you’d run:
sudo shutdown -r now
And to restart a Mac after a specific number of minutes (in this example, 15), you’d run:
sudo shutdown -r +15
Add a message for logged in users
If you want any logged-in users to know that the machine is being rebooted or shut down — and why — you can append a message to the end of your string. For example:
sudo shutdown -r +15 "This Mac is being restarted so that it can finish installing crucial updates."
In the above example, the Mac will restart 15 minutes after the command is run, and logged-in users will see the following message:
Shutdown at Fri Feb 1 15:47:46 2019.
shutdown: [pid 26582]
*** System shutdown message from charles@hotf***
System going down in 15 minutes
This Mac is being restarted so that it can finish installing crucial updates.
System shutdown time has arrived