Reboot remote Linux server sudo. Shutdown Linux from the command line

And sometimes, when debugging a problem or updating the kernel, it may be necessary to reboot the Linux system. If you have a standalone server, you need to know how to reboot the system from command line.

On modern distributions, the systemctl utility replaces most of the power management commands used on older Linux distributions with sysvinit. The old reboot and shutdown commands are systemctl aliases and are available on the system for compatibility reasons.

In this article, we will show you how to use the systemctl and shutdown commands to reboot a Linux machine. Commands must be run as root or user with .

How to reboot Linux using systemctl command

To reboot a Linux system, run the systemctl utility with the reboot command:

sudo systemctl reboot

The system will restart immediately.

When a reboot is initiated, all registered users and processes are notified that the system is going down and no further logins are allowed.

To prevent the reboot command from sending a message, run the command with the --no-wall option:

sudo systemctl --no-wall reboot

If you want to set a custom message explaining the reason for the reboot, use the --message= option:

sudo systemctl --message="Update Hardware" reboot

The message will be shown in the logs:

System is rebooting (Hardware update)

How to reboot Linux using the shutdown command

To reboot a Linux system, use the shutdown command with the -r option:

sudo shutdown -r

By default, the system will reboot after 1 minute, but you can specify the exact time you want the system to reboot.

The time argument can take two different formats. It can be an absolute time in the format hh:mm and a relative time in the format +m where m is the number of minutes since now.

The following example will schedule a system reboot at 10 am:

sudo shutdown -r 10:00

To immediately shut down your system, use +0 on its now alias:

sudo shutdown -r now

To send your own message along with the standard shutdown notification, enter your message after the time argument.

The following command will shut down the system after 10 minutes and notify users that a hardware update will be performed.

It would seem, what could be easier? All you have to do is turn off or restart the Linux server. To turn off, just enter the command

sudo shutdown -h now

To reboot

Sudo shutdown -r now

sudo reboot

These events, even in technical terms (not touching on the accompanying organizational issues), only at first glance may seem simple. But experienced system administrators know that for any OS, even a regular and correct restart can lead to negative consequences. This is largely due to the quality of maintenance and operation preceding the restart. Therefore, you need to understand that the most common reboot or shutdown of Linux. Without exaggeration, they are quite responsible actions. And administrators should always remember this.

Restarting and shutting down the system - why is it so important?

Linux operating systems are trusted to work, which should ensure the long-term and reliable operation of complex units, process plants, database servers (DB), web servers, etc., which are used by a large number of users, operators and maintenance personnel. Shutting down and restarting is inevitable for any system. But these activities should be carried out with minimal risks. Both for tasks performed by servers and for users.

Once UNIX and Linux were quite sensitive to restarts. But with the advent of highly reliable journaled file systems (FS), doing a shutdown or restart has become much safer. However, the possibility of damage to the configuration or the OS itself due to incorrect shutdown of the computer (or server) is not completely excluded. For example, an abnormal shutdown of database servers very often leads to a violation of data integrity and damage to tables. It does not matter which database management system (DBMS) is used to service them. Problems that arise in Linux are usually quite difficult to detect. Because the architectural features of Linux itself allow it to function even in the presence of complex collisions. But when it comes time to restart the OS, often these hidden problems immediately appear. Which is often accompanied by collapse.

Experienced system administrators know that when any changes are made to the system, such as modifying startup scripts, configuration of individual components, etc., it is very desirable to restart to make sure that the system works normally after these changes. Well, be sure to check so as not to miss the appearance of hidden and difficult problems. At the same time, you need to remember that problems may not appear immediately and not even after a couple of weeks - a lot of factors affect this and it all depends on the specific situation.

shutdown command

This command allows you to safely and technically "correctly" restart, stop the OS, or transfer it to single-user mode. For different systems the command shutdown has a different specification regarding syntax and options, so it is wise to review it in general terms, touching on only some of the specifics of use.

Because activities such as restarts and shutdowns often affect many users, system administrators need to be able to warn them of these actions in advance before they are performed. Command shutdown allows you to do this by adding a puz during which messages about an upcoming event (shutdown or restart) are sent to users. By default, these messages are sent at shorter time intervals and contain text about the nature of the upcoming event, for which the remaining time is also indicated. The administrator can set an arbitrary message text, if necessary, depending on the situation. Naturally, after performing shutdown, users will not be able to log in, but all this time they will see an informational message given through the command shutdown.

The nature of the action to be performed shutdown is set through parameters and these can be:

  • normal stop;
  • normal stop followed by automatic start (reboot);
  • switching to single-user mode;
  • some other related actions (depending on the system), such as checking storage devices with the command .

In the latter case, checking fsck can be forced, because by default in modern operating systems this check is carried out automatically at startup only in case of incorrect unmounting of file systems.

The following table lists the main options shutdown for some Linux systems:

System Way R H S F
linux /sbin/shutdown -r -h -f
Solaris /usr/sbin/shutdown -i6 -i0 -iS
HP-UX /etc/shutdown -r -h
AIX /sbin/shutdown -r -h -m

The following symbols are used for this system: R - restart, H - normal stop, S - continue in single-user mode, F - disable check fsck(only relevant for SUSE and Red Hat).

In order to stop Linux at 8:30 (for example, for routine maintenance of servers) and notify users about it, run the following command:

$ sudo shutdown -h 08:30 "Attention! Maintenance is being carried out from 08:30 to 13:00. We apologize for the inconvenience."

If you want to set a relative stop/restart time:

$ sudo shutdown -h +30 "Attention! Maintenance in progress."

halt and reboot commands

These commands should be considered in the context of the fact that although they can be used independently by themselves, they are usually called by the same command. shutdown.

When called halt all the basic steps necessary for the normal shutdown of the OS are performed. For example, all non-critical processes are terminated first, a shutdown message is written to the log, then the sync system call is executed and waiting for the storage devices to be freed from write operations. Then the work of the system kernel stops.

One of the important options halt is the key -n. It disables the system call sync so that the kernel does not restore the "old" images of the root partition stored in its cache. In other words, halt-n used after the partition has been restored with .

Command reboot differs from halt only by the fact that it restarts by default. However, it can be used to perform some useful action before rebooting the system. For example, you can not send messages about the upcoming reboot (it is worth noting that this is not always useful ...) to users using the key --no-wall. If you just need to record an event in a file /var/log/wtmp(this file registers all entry and exit events in the OS), then you need to use the key -w(or --wtmp-only), and no reboot will occur. To perform a reload without writing to a file /var/log/wtmp, there is a key -d(or --no-wtmp). Also with the command reboot it is possible to stop the system and turn off the machine using the keys —halt And -p (--poweroff) respectively. The key is used for forced and immediate reboot. -f (--force). On most systems, all switches described for the command reboot apply to the command halt with the same meaning.

If you find an error, please highlight a piece of text and click Ctrl+Enter.

The Linux shutdown command allows you to shutdown, reboot, or schedule a shutdown of your system. This article explains the most common and useful examples of the Linux shutdown command.

shutdown command syntax

Before we see the use of the shutdown command, let's first look at its syntax. shutdown
  • options: you can specify if you want to stop, power down, reboot, etc.
  • time: you can specify when to shutdown
  • message: you can send a custom message to all registered users

Note

The shutdown command needs superuser privileges. Therefore, you must either be root or run the command with sudo.

5 practical examples of the shutdown command in Linux

Now that you know the syntax of the shutdown command, let's see how to use it.

If you just use the shutdown command, it will start the shutdown process after one minute. So remember that the default time interval for the shutdown command is one minute.

Sudo shutdown Shutdown scheduled for Mon 2018-11-19 23:46:21 UTC, use "shutdown -c" to cancel.

Unsuspecting Linux users expect the shutdown command to shut down the system immediately, but when they see a message such as the timestamp in UTC, they are often confused.

1. Immediate shutdown of the system.

You don't always have to wait a minute for the system to shut down. You can shut down your system immediately by specifying a scheduled time +0 or now .

sudo shutdown now

2. Schedule a system shutdown

You can schedule a stop in the future by providing a time argument in either +t or hh:mm format.

For example, if you want to shutdown the system after 20 minutes, you can use this command:

sudo shutdown +20

If you want to shutdown the system at 3pm, you can use it like this:

sudo shutdown 15:00

Needless to say, the reference time and timezone are the system time.

Note

Five minutes before the scheduled shutdown time, the system will not allow login activity. This means that a new user cannot log in until five minutes after a scheduled shutdown.

3. Reboot the system with the shutdown command

There is a separate reboot command, but you don't have to learn a new command just to reboot the system. You can use the Linux shutdown command to reboot.

To reboot the system using the shutdown command, use the -r option.

Sudo shutdown -r

The behavior is the same as a normal shutdown command. It's just that instead of shutting down the system, it will be restarted.

So, if you used shutdown -r without any time arguments, it will reboot in one minute.

You can schedule a reboot in the same way as you would for a shutdown.

Sudo shutdown -r +45

You can also immediately reboot the system with the shutdown command:

Sudo shutdown -r now

4. Sending a custom message

If you are working in a multi-user environment and there are multiple users logged in, you can send them your own broadcast message with the shutdown command.

By default, all registered users will be notified of the scheduled outage and time. You can set up a broadcast message in the shutdown command itself:

sudo shutdown 15:00 "The system will be shut down to upgrade hardware, please save your work"

You can use the shutdown command with the -k option to initiate a "fake shutdown". It will not shutdown the system, but a broadcast message will be sent to all registered users.

5. Cancel scheduled shutdown

If you have planned a shutdown, you don't have to live with it. You can always cancel the shutdown with the -c option.

Sudo shutdown -c

And if you passed a scheduled shutdown message, how good System Administrator, you can also notify other users to cancel a scheduled shutdown.

sudo shutdown -c "scheduled shutdown has been canceled"

Halt vs Power off

Halt (option -H): terminates all processes and shuts down the CPU,
Power off (option -P): Very similar to stopping, but also turns off the block itself.

Historically, earlier computers were used to shut down the system and then print a message like "now shut down normally" and then the computers were turned off using physical switches.

These days, termination should automatically power off the system thanks to ACPI support.

These were the most common and most useful examples of the Linux shutdown command. I hope you have learned how to disable a Linux system via .

If you have any questions or suggestions feel free to let us know in the comments section.

This article is aimed at the most new to Linux and those who are interested in how to reboot Linux from the console. For me, restarting the computer in the terminal or using the graphical interface is elementary, but this is the base, not all beginners know it and I need to write about it.

Today we'll cover issues such as the command to reboot Linux from the console, reboot remotely, and directly reboot in the graphical interface. Let's start with the usual reboot of the system.

Here, as they say, what could be easier. Consider first rebooting in Ubuntu Unity. Just click on the gear button in the upper right corner of the screen, and select the item Shutdown:

Then, in the window that opens, click on the item:

In the Gnome desktop environment, everything is very similar to Unity, but in KDE you need to open the main menu, go to the tab output, and select the item reload:

Then confirm reboot.

And here the scope is much wider, there are about a dozen commands that can be used to reboot Linux. Some need root privileges, others don't, some look simple and easy to remember, while others are long and complicated. Next, we will look at all of them.

The first Linux reboot command, the most common and simplest:

As you can see, the utility needs superuser rights. After pressing Enter, the computer will immediately go into reboot.

The shutdown utility, which is used to shut down, also allows you to restart the computer; for this, you need to pass the -r parameter to it. Plus, you can also specify the reboot time. Now - 0 or now, after one minute +1 after two - +2, and so on:

sudo shutdown -r +1

In initialization systems compatible with Init Scripts, there were system boot levels - 0,1,2,3,4,5,6, level 0 - meant shutdown, 6 reboot, other modes of the system are not of interest to us now. You can switch between levels with the init command. But again, you need superuser rights. In this way:

The dbus system message service can also restart the computer:

/usr/bin/dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart

You no longer need superuser rights. These were the usual ways to reboot Linux, but there is one more, non-standard or even two. These are the magic SysRq keys. The Linux kernel listens for certain key combinations being pressed, and in response to them executes necessary actions. First enable sysrq support:

echo 1 > /proc/sys/kernel/sysrq

It is better to do this in advance, since this method is useful when the system is frozen and does not react to anything:

nano /etc/sysctl.conf

kernel.sysrq=1

To activate SysRq combinations hold Alt + SysRq and press the key code. For a normal reboot, it is recommended to use the following sequence: R E I S U B, press the keys in the same sequence with an interval of about a second.

  • R- returns keyboard control if the X server was terminated incorrectly;
  • E- the kernel sends a SIGTERM signal to all processes except init;
  • I- sends a SIGKILL signal to all processes except init;
  • S- the kernel synchronizes file systems, all data from the cache is transferred to the hard disk;
  • U- remounts all file systems in read-only mode;
  • B- immediate reboot, without synchronization, and additional preparations.

Before rebooting, the system waits for all processes to terminate, stops all services, unmounts and mounts read-only file systems. This is what we do by pressing these key combinations in sequence. But if you need to reboot the system now without waiting for the shutdown of all processes, for example, the server, you can immediately send a signal B. Like this: Alt+SysRq+B.

SysRq can be used without keyboard shortcuts by writing the desired operation code to the /proc/sysrq-trigger file:

echo b > /proc/sysrq-trigger

The system will be rebooted as is, without stopping services and preparing file systems, so unsaved data may be lost, and file system damaged.

If you have access to the server via ssh, then it is very easy to reboot linux remotely using one of the above commands, for example:

ssh [email protected]/sbin/reboot

But again, for this operation, you need to have root rights on the remote server.

conclusions

Now you know how to reboot linux, you even know how to reboot the server via ssh. If you have any questions, ask in the comments!

Related posts:


Let's consider how to restart or shut down the computer from the command line. I use this when, when installing a driver or under heavy load on the processor, the interface stops responding to my actions (although this happens extremely rarely). It is possible to kill the "gluttonous" process through the command line, but it is not always known which process it is, therefore fast decision it's a computer restart.

We restart the computer

I do so. Go to the console by pressing a keyboard shortcut Ctrl+Alt+F1. In the console, you must first enter your username and password (characters are not displayed when entering a password). And I execute the command:

sudo reboot

You will again need to enter the administrator password and press Enter. The computer will restart.

You can also use the command to restart your computer. shutdown, for this you need to use the key -r:

Sudo shutdown -r now

Turn off the computer

To turn off the computer from the command line, you need to run the command:

sudo shutdown -h now

You can also turn off the computer by running the command:

Sudo halt

And also can be used.