SSH restart Linux system using reboot command

I am a new Linux server system administrator. I can log in to my server using ssh keys for the root user. Can you tell me if it is safe to reboot Linux server using ssh. How can I use ssh to reboot the Linux box?

Yes, you can boot the machine or Linux server using ssh. The SSH is protocol. It associated with Secure Shell. In short, ssh is a client-server technology that allows secure remote login from one computer to another. The ssh client is a defacto standard in Linux and Unix world for managing servers. This page shows how to restart Linux system using ssh command.

How to login using ssh

The syntax is:
ssh user@server
ssh user@server-ip-address

For security reasons root login is always disabled on Linux servers. In that case login as normal user and use the su command or sudo command to gain root shell:
sudo -i

Verify with id command:
ssh restart system using reboot

SSH restart Linux system

Now, you know how to log in as root user using ssh command:
ssh user@linux-box
We will now reboot the Linux server using ssh. The syntax is as follows (use any one of the following command):
# reboot
# shutdown -r now
# shutdown -r 0

One can use the sudo command as follows:
$ sudo shutdown -r now
All of the above commands would reboot the machine. See “SSH Public Key Based Authentication on a Linux/Unix server” for more information.

SSH reboot command example

There is a shortcut too. You can use ssh to log in and run commands. The syntax is as follows when you log in as non-root user:
ssh -t "sudo reboot"
ssh -t "sudo shutdown -r now"

Of course, if you log in to Linux server as root user, avoid typing sudo:
ssh -t "reboot"
ssh -t "shutdown -r now"

Restarting Linux computer using ssh command line option

sudo: no tty present and no askpass program specified

If you skip the -t option to the ssh command, you will see an error that read as follows on screen:

sudo: no tty present and no askpass program specified

A note about rebooting a large number of Linux servers

You can use bash for loop as follows to reboot 5 servers named www1, www2, db1, db2, and cache1:

for s in www1 www2 db1 db2 cache1:
   ssh -t root@${s} "shutdown -r now"

And, there is an Ansible tool to reboot Linux machine or server with playbooks too. Say you want to reboot 100 AWS vms or servers. A bash for loop is slow and not very useful. Hence, you use an IT automation tool such as Ansible.


In this tutorial, you learned how to reboot the Linux machine using ssh. See shutdown(8) man page here for more info.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

Comments on this entry are closed.

Comments are closed. Still have questions? Post it on our forum