As a sysadmin, one of the things you’ll need to do sooner than later is reboot a server via SSH. Even though it’s easy to do once you figure out how, it’s importance makes it worth learning about. This operation can be essential for maintaining your server’s performance and reliability, assisting you in recovering from a variety of issues including software crashes or even configuration modifications that only take effect after a reboot. In this blog post, we’ll go over a few different SSH server restart techniques as well as offer some helpful advice and information to get you started.
Restarting a Server via SSH:
To restart a server using SSH, you’ll need to connect to it first. You can do this with any SSH client such as PuTTY. Just login to the server’s hostname or IP, using your username and password. The account you login with should have administrative or root privileges, or you can “sudo” to gain those privileges.
After you’ve logged in, the simplest way to restart a server, is simply with the command “reboot”:
As mentioned before, this will only work if you have the necessary permissions. Ordinarily this requires you login in as root, or a user that’s been given root privileges. Keep in mind that th “reboot” command will reboot the server right away, by telling all processes to gracefully save their work and exit.
Beyond the simple “reboot” command, there are several other ways to restart a server while connected to SSH. For example, you might use these if you want to reboot or shutdown the server at a scheduled time. The relevant commands include
Now let’s look at the shutdown command. With this command it’s possible to schedule a shutdown or restart for a future time, and you can choose between shutting down or restarting the server. To immediately reboot the server (much like with the reboot command), the following options can be used with “shutdown”:
shutdown -r now
Next, let’s look at the init command. This command can be used to shut down and restart the server, as well as to perform other tasks related to the initialization process. Again, to behave the same way as the “reboot” command, the following example uses init to reboot the server immediately:
Finally, let’s consider the
systemctl command. systemctl is commonly used to start, stop, or restart different system services, but it can also be used to reboot the server entirely. Again, to immediately reboot the server the same way the “reboot” command does, you can use systemctl as follows:
If you want to use some of the more advanced features of these commands, such as scheduling, we suggest reading the “man” page for the command you’re interested in. Linux man pages can be opened by typing “man” before the command, such as:
In this article, we covered how to restart a server via SSH. We hope you learnt something new. Although it can appear to be a straightforward task, there are still nuances that even experienced server administrators can benefit from knowing. You can be better equipped to deal with any issues that might emerge with your server by studying the various techniques and commands that can be used to restart a server via SSH.