How to Restart Ubuntu From Terminal

How to Restart Ubuntu From Terminal

Ubuntu is a well-known distribution of Linux particularly praised for its ease, versatility, and wide-ranging features. Although many users prefer to interact with Ubuntu via its graphical user interface (GUI), the terminal continues to be a key way of administering and controlling the computer. One important function that can be done via the terminal is restarting the system. Whether you’re updating, troubleshooting, or managing a remote server, being able to restart Ubuntu from the terminal is important and incredibly useful.

In this article, we explore Ubuntu’s terminal and its many features, permissions, and even safety measures that one needs to take, with a focus on commands that will restart the system.

Why Restart Ubuntu From the Terminal

Let’s understand why you might want to restart Ubuntu terminal:

  1. When managing a server via SSH, the terminal is your only interface.
  2. Some updates require a reboot to take effect.
  3. Restarting can help resolve system glitches or frozen applications.
  4. Scripts and cron jobs may include reboot commands for maintenance tasks.
  5. If the graphical interface crashes, the terminal provides a reliable alternative.

Easy Management of DNS Records is Here!

Your search for a reliable hosting service ends now! You have Hostonce to rely on. We are a smart alternative for better reiliability, support, speed, and management!

Accessing Terminal

There are several ways to open the terminal in Ubuntu:

  • GUI Method: Press Ctrl + Alt + T to open a terminal window.
  • TTY Console: Press Ctrl + Alt + F3 to switch to a full-screen terminal (use Ctrl + Alt + F2 or F1 to return to the GUI).
  • SSH: Use ssh username@hostname to access a remote Ubuntu system.

Understanding Permissions

Restarting the system is a privileged operation. You must have root access or use sudo to execute reboot commands. If you’re not logged in as root, prepend commands with sudo. For Example:

sudo reboot
sudo reboot

You’ll be prompted to enter your password to confirm the action.

Common Commands to Restart Ubuntu

Here are the most commonly used terminal commands to reboot Ubuntu from command line:

reboot

The simplest and most direct way to restart Ubuntu.

sudo reboot
  • Function: Immediately initiates a system reboot.
  • Use Case: General-purpose restart.
  • Note: May terminate active sessions without warning.

shutdown -r now

This command is part of the shutdown utility and includes the -r flag to reboot.

sudo shutdown -r now
sudo shutdown
  • Function: Shuts down and restarts the system immediately.
  • Use Case: Preferred when you want to notify users or log shutdown events.
  • Note: You can also schedule a restart.

Example:

sudo shutdown -r +10 "System will restart in 10 minutes for maintenance."

systemctl reboot

sudo systemctl reboot
systemctl reboot
  • Function: Tells systemd to reboot the system.
  • Use Case: Modern and recommended method for systemd-based systems.
  • Note: Offers more control and integration with system services.

init 6

This is a legacy command from the older SysV init system.

sudo init 6
  • Function: Changes the system runlevel to 6, which triggers a reboot.
  • Use Case: Legacy systems or compatibility scenarios.
  • Note: Not recommended for modern Ubuntu versions.

halt and poweroff

While these commands are used to shut down the system, they can be combined with reboot flags.

sudo halt --reboot
sudo poweroff --reboot
  • Function: Halts or powers off the system, then reboots.
  • Use Case: Advanced scripting or specific shutdown procedures.

Restarting Specific Components

Sometimes, you don’t need to restart the entire system. You can restart specific services or components:

Restarting the GUI

If your graphical interface freezes, restart the display manager:

For GNOME (default in Ubuntu):

sudo systemctl restart gdm

For LightDM:

sudo systemctl restart lightdm

For SDDM (KDE):

sudo systemctl restart sddm

Safety Tips

Restarting a system can disrupt active processes and users. Follow these precautions:

  • Ensure all files and applications are saved.
  • If on a multi-user system, warn others before rebooting.
  • Use top or htop to monitor active tasks.
  • Use logger to record the reboot event.
logger "System reboot initiated by user $(whoami)"

Automating the Restart Procedure

To automate restarts at regular intervals, use cron:

Edit the crontab:

sudo crontab -e

Add a line to restart daily at 2 AM:

0 2 * * * /sbin/reboot

Final Thoughts

Restarting Ubuntu from the terminal is a straightforward yet powerful operation. Whether you’re managing a personal desktop, a remote server, or an enterprise system, mastering these commands enhances your control and efficiency. Always remember to use caution, especially on multi-user systems or production environments.

By understanding the various methods and their implications, you can choose the most appropriate command for your situation. And with automation tools like cron and at, you can even schedule reboots to maintain uptime and performance.

FAQ

Use the command sudo reboot to restart Ubuntu from the terminal.

Both restart the system, but shutdown -r now gives more control over timing and user warnings.

Yes, administrative (sudo) privileges are required to execute reboot commands.

Yes, use sudo shutdown -r +10 to restart in 10 minutes.

No, restarting from the terminal does not save open applications or documents, save your work first.

Post a Comment

Your email address will not be published. Required fields are marked *