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
ssh root@server1.cyberciti.biz
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:
ssh vivek@server1.cyberciti.biz
sudo -i
Verify with id command:
id
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 vivek@server1.cyberciti.biz "sudo reboot"
ssh -t vivek@server1.cyberciti.biz "sudo shutdown -r now"
Of course, if you log in to Linux server as root user, avoid typing sudo:
ssh -t root@server1.cyberciti.biz "reboot"
ssh -t root@server1.cyberciti.biz "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: do ssh -t root@${s} "shutdown -r now" done
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.
Conclusion
In this tutorial, you learned how to reboot the Linux machine using ssh. See shutdown(8) man page here for more info.
🐧 1 comment so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Still have a problem rebooting the Linux server? Try our forum to get help.