Linux: How to Log Out, Reboot, and Shut Down
To end the current shell in Linux, you can use exit; to reboot the system, use sudo systemctl reboot; and to power off, use sudo systemctl poweroff. Logging out affects only the current session, while rebooting and shutting down also affect other users and services on the server.
Check Before Execution
The reboot and shutdown examples in this article are based on Linux using systemd. Commands executed immediately can affect unsaved work and running services, so save your work, inform other users, and perform them during maintenance hours. On servers, check backups and impact on services.
If you are connected via SSH, the commands are executed on the server you connected to, not on your PC. The following commands help verify the target.
hostname
date
who
hostname shows the current host name, date shows the server's current time and time zone, and who shows a list of users displayed in login records. You cannot fully identify the server by name alone, so also cross-check with the management tool information. Remote servers will disconnect SSH connections during reboot, and after shutdown, there may be no way to turn them on directly, so check the console or power management path in advance.
Log out of the current shell
To exit the current shell, execute the following command.
exit
When run in the last shell of an SSH session, it usually closes the remote connection. If you are in a nested shell, return to the outer shell first. logout can be used when exiting a login shell, but may not work in a typical non-login shell. Logging out does not shut down the system itself, and whether ongoing tasks continue depends on the session and task settings.
Reboot or shut down immediately
On a systemd system, the following command requests a reboot. Services begin stopping immediately upon execution, so make sure the target is correct first.
sudo systemctl reboot
To shut down the system and turn off the power, use the following command.
sudo systemctl poweroff
Administrative privileges may require sudo or separate authentication depending on the environment. The power status and restart method of virtual machines or cloud servers may vary according to the management platform's policies. After rebooting, reconnect and check that the necessary services are functioning properly. halt, which stops the system, and poweroff, which powers it off, do not have the same meaning, so choose the command that suits your purpose.
Scheduling and canceling reboots or shutdowns
You can schedule operation with shutdown. The following command schedules a reboot for 10 minutes later.
sudo shutdown -r +10
-r is reboot, +10 is 10 minutes from the current time. To turn off the power 10 minutes later, use -P.
sudo shutdown -P +10
You can also specify a specific time with HH:MM in 24-hour format. For example, to schedule a reboot at 23:30 server time, run the following.
sudo shutdown -r 23:30
Before running, check the server time and time zone and ensure the desired time has not yet passed. Depending on the implementation and version, the handling of times that have already passed may differ, and some versions may start shutdown immediately. Entering a scheduled command affects the system, so do not run it on a production server just for testing.
To cancel a scheduled shutdown that has not yet started, execute the following command.
sudo shutdown -c
Cancellations apply to pending system shutdowns and may belong to another administrator, so please check first. This is not a command to undo an immediate reboot or shutdown that has already started. In some recent versions of systemd, you can view pending shutdowns with shutdown --show, but some versions may not have this option. For detailed behavior, check the man shutdown and systemd shutdown documentation of your system.
Sending notifications only and troubleshooting
systemd's shutdown -k sends notifications to logged-in users without actually shutting down or rebooting. For example, the following command sends a message with the time.
sudo shutdown -k +10 "Maintenance notice"
The way notifications are received may vary depending on user sessions and system settings, so important work announcements should also be delivered through separate channels. -k is not an actual scheduled shutdown.
- Permission error: Check sudo permissions and the system's authentication policy.
- Command or option differs: Since behavior can vary depending on the distribution and initialization system, check
man shutdownandman systemctl. - Failed to connect after reboot: Wait long enough and then check the power status, network, SSH, and essential service status from the management console.




