No operating system is perfect. Even if it was, there might be problems with drivers and apps. Linux is no exception. Despite being more stable than Windows (in many cases, not all!), there will probably come a time when you need to restart your Linux computer. This might be because something isn’t working. Alternatively, you might be connected via SSH to a remote computerHow to Remotely Manage a Linux Server with SSHHow to Remotely Manage a Linux Server with SSHSSH is very functional, which is why it's a go-to for remote server management. Learn how to remotely manage a Linux server via SSH, from connection, to installing software, and file transfers.Read More or server and want it to restart or shut-down completely.

But how might you do this? Several commands are available for you to power off or restart (or reboot) a Linux computer via the command line.

Let’s look at them in turn, and examine how and when these commands should be used.

1. Shutdown

If you’re done with your Linux box, the solution to simply shut it down is to use the shutdown instruction, sent via SSH (if you’re using a Windows PC, you have several SSH tools4 Easy Ways to Use SSH In Windows4 Easy Ways to Use SSH In WindowsSSH is the de facto solution for securely accessing remote terminals on Linux and other UNIX-like systems. If you have a remote SSH server you want to access, you'll have to download an SSH client....Read More to choose from). This can be used to either shut the computer off permanently (until such a time as you decide to reboot it) or to restart. The syntax for the command is:

shutdown [option] [time] [message]

For instance, to shut the computer down immediately, you would use:

shutdown -h now

Here, the -h means halt while now clearly means that the instruction should be carried out immediately. Different delays can be used. For instance, you might use +5 instead, which will tell the computer to run the shutdown procedure in five minutes.

If you want to include a message, this will be flashed up to all logged in users:

Remember that you can find the full list of switches for these commands by inputting:

[command] --help

Restart With -r

An alternative option is to use the -r command to restart the computer. This is used in place of the -h, so to restart a computer or server, you might use:

shutdown -r +5 "The server is restarting in five minutes, please save your work and log off."

Any scheduled shutdown or restart can be cancelled by inputting the -c cancel command:

shutdown -c

2. Reboot

As the shutdown command features a restart option, it should come as no surprise to learn that the reboot command has a shutdown option.

Image Credit: Anton Khegay via Shutterstock

The standard reboot command is:

reboot

This will prompt your computer to turn itself off, and back on again. However, should you wish to power off the device, then the -p switch will work:

reboot -p

Another option is to force a reboot. This can be useful if an app or service is hanging and you need to restart quickly:

reboot -f

This forcefully reboots your Linux box.

3. Halt

We’ve already seen the -h switch above, but halt can be used as a command all on its own. This will lead to the computer shutting down immediately, with a simple four letter word:

halt

The -f switch can also be used with halt, but the results are inconsistent, and can lead to system stability issues.

4. Poweroff

You might prefer the terminology of the poweroff command. This does exactly the same as halt, except it takes over twice as long to type.

However, as well as using -f to force poweroff, you can also employ the -w switch to log the system reboot call to /var/log/wtmp. This is a potentially useful debugging tool, as is –verbose, which can help with issues with shutdown.

poweroff --verbose

5. The Emergency Option: REISUB

All of the above commands can be used in situations when the system is running without any problems. But what if it crashes? What if the PC or server is hanging, and cannot be rebooted in the agreeable manner?

The answer then is a keyboard combination. If you’ve switched from Windows, you probably know that Ctrl + Alt + Del displays a menu with Shutdown as an option. If held for longer, the machine will shut down automatically. On a Mac, meanwhile, you would simply hold down the power button (an option that also works on Windows hardware6 Tips for Rebooting Windows Like a Pro6 Tips for Rebooting Windows Like a ProWindows' strength is customization and it doesn't stop at shutting down. You can end your session or reboot your system in various ways, many offering more convenience and control than the Start menu.Read More).

Image Credit: JanHetman via Shutterstock

In Linux, the keyboard combination is Alt + Print Screen + B to reboot. However, if this doesn’t work, or there is a more complex issue, you can alter the combination, using up to six keys.

This is known as REISUB, due to the following forced acronym:

unRaw — Takes control of the keyboard back from the X display server.

tErminate — Sends the termination signal SIGTERM to all processes, to terminate gracefully.

kIll — As above, but the SIGKILL signal, which forces immediate termination to processes.

Help, I Accidentally Shut Down My Linux PC or Server!

We’ve seen how to cancel a shutdown or restart command. However, it’s easy to find yourself initiating a shutdown command when a vital process is running — especially on a remote server. A way around this is to install molly-guard, which can override a shutdown by checking for certain parameters.

As molly-guard is running in the background, it will detect a command such as poweroff and report back that an SSH session has been detected. You then have the choice of entering the server’s hostname to confirm shutdown, or to press Ctrl + C to cancel. Useful!

Those five ways of shutting down a Linux computer from the command line are particularly useful as they can be used on the computer itself, or via a remote SSH. As these commands are so concise, they lend themselves to quick use — which might result in an accidental reboot from time to time! Fortunately, the molly-guard utility is enough to avoid this.

Have you tried molly-guard? Have a preferred method for rebooting your Linux device? Tell us in the comments.

I always thought it was CTRL + ALT+PRINT SCREEN (or SySRq) and then REISUB, not REIBUS. I was told an easy way to remember is REISUB is the word BUSIER spelled backwards. Unless that was a typo you printed in your column.

Christian Cawley is a Deputy Editor at MakeUseOf, covering security, Linux, DIY and programming, with extensive experience in desktop and software support. Christian is a regular contributor to Linux User & Developer magazine, as well as specials including Raspberry Pi for Beginners, and Raspberry Pi for Kids. He's a Raspberry Pi tinkerer, Android user, podcaster and foodie.