GICT knowledge base
How to use Reboot and Shutdown commands in Ubuntu Server
Published
Managing an Ubuntu Server often requires restarting or shutting down the system. These tasks are simple but must be performed correctly to avoid data loss or service interruptions. In this article, you will learn how to use the reboot and shutdown commands safely on your Ubuntu Server.
Why Reboot or Shutdown a Server?
There are several reasons you may need to restart (reboot) or power off (shutdown) your Ubuntu Server. Updates, hardware changes, troubleshooting, or regular maintenance are some of the common reasons. Performing these actions the right way helps prevent data corruption and ensures every running service closes properly.
Accessing Ubuntu Server
Before you can run any restart or shutdown command, you need access to the server. Usually, this is done through SSH (Secure Shell) if you are working on a remote system. On your local machine, you can use:
$ ssh username@server-ip-address
Replace username with your server username and server-ip-address with the server’s IP address.
Using the Reboot Command
The reboot command is the simplest way to restart your Ubuntu Server.
Step 1: Login to your server through SSH or the terminal
Step 2: Type the following command and press Enter:
$ sudo reboot
This will immediately restart the computer. If you are logged in remotely, your session will close once the server restarts.
Using the Shutdown Command
The shutdown command gives you more control. You can schedule when to shut down or restart, or send messages to users.
Shutdown the Server Immediately
Step 1: Access your server terminal
Step 2: Type:
$ sudo shutdown now
The server will start the shutdown process right away.
Shutdown at a Specific Time
Step 1: Open the terminal
Step 2: To shutdown after 10 minutes, use:
$ sudo shutdown +10
You can change +10 to any number of minutes or set a specific time using the format hh:mm.
Adding Messages with Shutdown
It’s helpful to inform users about the shutdown or restart. You can provide a custom message at the end of your shutdown command. This message will be broadcasted to all users currently logged in.
$ sudo shutdown +5 "System will shut down for maintenance. Please save your work."
In this example, all users get the notification that the server will shut down in 5 minutes and are asked to save their work.
Restarting with the Shutdown Command
You can also restart the server using the shutdown command with the -r option.
Step 1: Make sure you have saved your work
Step 2: To restart immediately, enter:
$ sudo shutdown -r now
To add a notification message during a scheduled restart:
$ sudo shutdown -r +15 "Server will restart in 15 minutes for updates."
Cancel a Pending Shutdown or Restart
If you scheduled a shutdown or restart and want to stop it, use the command below. You can also provide a message for all users, letting them know that the planned action was canceled.
$ sudo shutdown -c "Scheduled shutdown canceled. No action will be taken."
This notifies all users that the upcoming shutdown or restart has been called off.
Force Shutdown or Reboot
If the system is not responding, you can use the -f (force) option. Be careful as this can cause data loss.
$ sudo reboot -f
$ sudo shutdown -P now
The -P flag tells the system to power off (same as a full shutdown).
Quick Reference to Useful Commands
- Restart immediately:
sudo rebootorsudo shutdown -r now - Shutdown immediately:
sudo shutdown now - Schedule shutdown (10 mins):
sudo shutdown +10 - Schedule shutdown with message:
sudo shutdown +10 "System maintenance soon." - Cancel scheduled shutdown or restart with message:
sudo shutdown -c "Shutdown canceled." - Force shutdown:
sudo shutdown -P now - Force reboot:
sudo reboot -f
Best Practices
- Always save your files before shutting down or rebooting.
- Notify users if a server shutdown or restart is planned, especially on shared systems.
- Run system updates before restarting if they require a reboot.
- Use the commands with
sudoto ensure you have the right privileges. - Whenever possible, use messages to inform users about upcoming server downtime.
Conclusion
Shutting down and rebooting an Ubuntu Server is straightforward using the reboot and shutdown commands. Use these tools for regular maintenance and emergency troubleshooting. Always remember to inform users and back up important work before taking these actions. With the correct use of shutdown messages, you can keep every server user prepared for downtime or restart events.
Related guides
How to Restrict an SSH Key to One Command
Restrict an SSH key to one command with authorized_keys options. Protect the command and check that unwanted shell and forwarding access are denied.
Linux and CommandsSelf-Hosted Video Processing With FFmpeg: A Practical Guide
Learn how to self-host video processing on a VPS using FFmpeg, with practical commands for conversion, compression, thumbnails, and automated workflows.
Linux and CommandsHow to use nohup: Commands in Linux That Survive Terminal Closes
Keep commands running after you close the terminal. nohup examples with wget, Python, rsync, and Docker on any VPS.
Linux and CommandsHow to Fix “Too Many Open Files” Error on Linux Servers
Learn how to fix the "Too Many Open Files" error on Linux servers by understanding file descriptors, adjusting limits, and diagnosing leaks effectively.
