Safely Shut Down a Linux Server: Essential Checks and Commands
This guide explains how to safely shut down or reboot a Linux server by checking logged‑in users, running processes, and network connections, notifying users, running sync, and using the appropriate shutdown, reboot, halt, or poweroff commands with their key options.
Overview
Linux is a multi‑user system; shutting down by pressing the power button can terminate other users' sessions or programs, potentially damaging the file system. Proper shutdown knowledge is needed for patching, rebooting, or avoiding data loss.
Pre‑shutdown Checks
1. Check logged‑in users with the who command.
[root@Zabbix6 ~]# who
root pts/0 2024-01-02 10:02 (192.168.80.22)Perform shutdown or reboot during off‑peak hours to minimize impact.
2. View running processes with ps -aux. The ps command displays processes, status, PID, CPU and memory usage, and more.
-a: show all processes, including those of other users.
-u <user>: show processes of the specified user.
-x: show processes without a controlling terminal.
-e: show all processes (same as -A).
-f: detailed information including PID, PPID, CPU and memory usage.
-l: long format with PID, PPID, state, CPU time, command.
-p: show information for the specified PID.
-t <terminal>: show processes on the specified terminal.
-C <command>: show processes with the specified command name.
[root@Zabbix6 ~]# ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 241964 14820 ? Ss 2023 2:33 /usr/lib/systemd/systemd --switched-root --system --deserialize 18
root 2 0.0 0.0 0 0 ? S 2023 0:02 [kthreadd]
... (output truncated for brevity)3. Check current network connections with the netstat command, which shows routing tables, active connections, and interface status.
[root@Zabbix6 ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:zabbix-agent 0.0.0.0:* LISTEN
... (output truncated for brevity)4. Notify online users about the upcoming shutdown or reboot.
Common Shutdown Commands
1. shutdown command – used to power off or reboot the system. Only root can execute it. Common options:
-h: halt (power off).
-r: reboot.
-t: set countdown time in seconds.
-k: send warning message without executing.
-c: cancel a scheduled shutdown/reboot.
Syntax:
shutdown [-krhc] [time] [message] # Immediate halt
[root@localhost ~]# shutdown -h now
# Immediate halt using 0
[root@localhost ~]# shutdown -h 0
# Specific time (24‑hour format)
[root@localhost ~]# shutdown -h 11:00
# Halt after 10 minutes
[root@localhost ~]# shutdown -h +10
# Reboot now
[root@localhost ~]# shutdown -r now
# Reboot with warning message
[root@localhost ~]# shutdown -r now 'This system will reboot'
# Cancel scheduled shutdown
[root@localhost ~]# shutdown -c2. reboot command – restarts the system, equivalent to shutdown -r.
# Reboot
[root@localhost ~]# reboot
# Force reboot
[root@localhost ~]# reboot -f3. halt command – similar to shutdown, used to halt the system.
# Halt
[root@localhost ~]# halt4. poweroff command – powers off the system.
# Power off
[root@localhost ~]# poweroff5. sync – flushes memory buffers to disk to prevent data loss before shutdown. It is automatically run before shutdown/reboot, but can be executed manually for safety.
# Sync buffers
[root@localhost ~]# syncSummary: Proper shutdown or reboot requires confirming users, processes, and network connections, notifying users, running sync, and using the appropriate command such as shutdown or reboot with the correct options.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Linux Cloud Computing Practice
Welcome to Linux Cloud Computing Practice. We offer high-quality articles on Linux, cloud computing, DevOps, networking and related topics. Dive in and start your Linux cloud computing journey!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
