Have you ever had a need to shut down your Mac, but, for one reason or another, you couldn’t actually do it? You might be wondering how that could be—consider a situation where you’ve left your work machine on, so you can use Remote Login (in the Sharing System Preferences panel) to login to it later from home. While driving home, your recall that maintenance was going to shut down power to the building this evening—and there’s your Mac, sitting there with 15 open applications, innocently awaiting its impending power failure. You could, of course, turn around and drive back to the office. But assuming you’ve got another machine at home, and have enabled remote login to your work machine, you can just continue on home and shut down your work Mac from there.
If you’ve planned ahead, you’ve enabled remote GUI control by using the Sharing System Preferences panel—see
this Mobile Mac column
for more detail on how to set that up. Assuming you’ve done all this, then you can just connect to the remote Mac’s GUI, and pick Shut Down from the Apple menu.
But what if you’re not so good at planning, and you’ve only left the machine with Remote Login enabled? Then you’ll want to use the Unix command fittingly named
shutdown. This command will shut down the remote Mac, and it has a number of useful options.
Here’s how it works. First, you must connect to the remote Mac, typically via
ssh, which is enabled using the Remote Login option of the Sharing System Preferences panel. This also implies that the remote Mac must be reachable through any firewalls that might exist between the two machines. On the machine being used to shut down the remote Mac, you’d type something like
ssh -l username 220.127.116.11, replacing
with the proper user name and IP address for the remote machine.
Once you’re connected, you need to execute the
command as the root (superuser) user. But before we shut down the machine, let’s look at some of the various forms of
shutdown -h +10 “Shutting down soon!”: The
option tells the system to shut down;
means in 10 minutes;
Shutting down soon!
is the message any users who have Terminal open will see.
shutdown -h 0612082000 “Shutting down at 8:00pm tonight”: Instead of specifying the relative time until shutdown, you can specify the precise time, using the
format, and using a 24-hour clock for the time.
shutdown -r +15 “Rebooting in 15 minutes”: The
option reboots, rather than shuts down, the system.
shutdown now: Shuts down the system immediately.
There are other options available as well; type
in the GUI to read about them. As I noted earlier, you have to run these commands as root, so you’ll need to put
in front of it (i.e.
sudo shutdown now
), and provide your admin password when asked.
Keep in mind that, although this will give you a “clean” shut down (the system will make sure that everything happens in an orderly manner), anything running in the GUI will simply quit—even if you have open documents with unsaved changes. Let me repeat that: unsaved changes in documents open in the GUI
will be lost!
There are other scenarios where this trick is useful, too. One that comes to mind is using it to safely shut down if your display goes kaput. Just remotely login from another Mac and use this command to shut the machine down in a safe manner.