reboot linux from command line

How to Restart Linux Server from Command Line

Sometimes you may need to restart or reboot Linux server from command line. In this article, we will look at how to restart Linux server from terminal or command line interface.


How to Restart Linux Server from Command Line

There are different ways to restart Linux server from command line. We will look at each of them one by one.


Using Shutdown

Open terminal and run the following command to shutdown your Linux system

$ shutdown

If you want to reboot your machine instead, use shutdown command with -r option.

$ shutdown -r

If you do not have sufficient privileges to run shutdown command, then use sudo before the command.

$ sudo shutdown

If you want to shutdown or reboot a remote machine then use shutdown command along with ssh command. Replace server.com with the remote server’s IP or domain. Replace user with the username of remote user.

ssh –t user@server.com ‘sudo shutdown’

You will be asked to provide password for the remote user.


Using Reboot

You can alternatively use reboot command to reboot your Linux system

$ reboot

If you do not have enough privileges to run reboot command, you can do so with sudo.

$ sudo reboot

You can also call reboot command on remote server using ssh command as shown below.

ssh –t user@server.com ‘sudo reboot’


Automate Shutdown

If you want to shutdown or reboot your system at a specific date/time, you can schedule them using cronjob. Open crontab with the following command.

$ crontab -e

Add the following line to schedule reboot every day at 10.a.m.

0 10 * * * reboot >/dev/null 2>&1

Save and close the file.

In this article, we have looked at how to reboot or restart your Linux system from command line.

Also read:

How to Flush DNS Cache in Windows, Mac, & Linux
How to Change Hostname in Debian/Ubuntu
How to Send GET & POST requests in Python
How to Create Swap File in Ubuntu
SFTP Script to Transfer File in Linux

Leave a Reply

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