Hot answers tagged

76

Anyone can execute shutdown, but triggering a system shutdown requires root privileges. But shutdown is not setuid, and so only root can successfully execute it. The shutdown program is nice enough to check your privileges and let you know if there is a problem, but even if it naively tried a system shutdown, nothing would happen. GLENDOWER: I can call ...


58

Warning: by the end of this answer you'll probably know more about linux than you wanted to Why reboot and poweroff require root privileges GNU/Linux operating systems are multi-user, as were its UNIX predecessors. The system is a shared resource, and multiple users can use it simultaneously. In the past this usually happened on computer terminals ...


50

Generally, one uses the shutdown command. It allows a time delay and warning message before shutdown or reboot, which is important for system administration of multiuser shell servers; it can provide the users with advance notice of the downtime. As such, the shutdown command has to be used like this to halt/switch off the computer immediately (on Linux and ...


50

You can do this directly from the shutdown command, see man shutdown: SYNOPSIS /sbin/shutdown [-akrhPHfFnc] [-t sec] time [warning message] [...] time When to shutdown. So, for example: shutdown -h 21:45 That will run shutdown -h at 21:45. For commands that don't offer this functionality, you can try one of: A. Using at The at daemon ...


47

Try the following commands: Display list of last reboot entries: last reboot | less Display list of last shutdown entries: last -x | less or more precisely: last -x | grep shutdown | less You won't know who did it however. If you want to know who did it, you will need to add a bit of code which means you'll know next time. I've found this resource ...


47

And now, the systemd answer. You're using, per the tag on your question, Red Hat Enterprise Linux. Since version 7, that has used systemd. None of the other answers are correct for the world of systemd; nor even are some of the assumptions in your question. Forget about runlevels; they exist, but only as compatibility shims. The systemd documentation ...


44

Linux has its origins in Unix and Unix was initially developed as a multi-user operating system. You could have one user disrupt other users by wanting to reboot the system. Only the administrator with root privileges could do that.


41

There is no difference in them. Internally they do exactly the same thing: reboot uses the shutdown command (with the -r switch). The shutdown command used to kill all the running processes, unmount all the file systems and finally tells the kernel to issue the ACPI power command. The source can be found here. In older distros the reboot command was ...


35

Its quite natural and a policy matter and convenience, it had been allowed from GUI because you are physically logged in to the machine. ( Some Linux distributions will still ask you for password if the GUI is not running as root , I am using Centos 6 and there is even no GUI shutdown/reboot option for my user , there is only log out and lock option) From a ...


31

The hardware power button triggers an ACPI event that acpid (the ACPI daemon) notices and reacts to; in this case by shutting down the system, although you could have it do whatever you want. The ACPI daemon runs as root, so it has permission to shutdown the system. Desktop environments (e.g. gdm for Gnome) typically run as root as well, so I suspect they ...


27

It doesn't get much faster than using the System Request (SysRq) functionality and then triggering an immediate reboot. This is a key combination understood by the kernel. Enable SysRq: echo 1 > /proc/sys/kernel/sysrq Now, send it into reboot. echo b > /proc/sysrq-trigger b - Immediately reboot the system, without unmounting or syncing ...


24

Linux Mint is based on Ubuntu, so I'm guesing the runlevel system is probably the same. On Ubuntu, scripts for the different runlevels are executed according to their presence in the /etc/rc[0-6].d directories. Runlevel 0 corresponds to shutdown, and 6 to reboot. Typically the script itself is stored in /etc/init.d, and then symlinks are placed in the ...


23

It's a bit historical. halt was used before ACPI (which today will turn off the power for you)*. It would halt the system and then print a message to the effect of "it's ok to power off now". Back then there were physical on/off switches, rather than the combo ACPI controlled power button of modern computers. poweroff, naturally will halt the system and ...


22

It depends you started task. If it is some command line tool you could simply run halt or shutdown -h now: wget http://..../somelargefile; halt - halt will be executed after wget wget http://..../somelargefile && halt - halt will be executed if wget return no errors wget http://..../somelargefile || halt - halt will be executed if wget return ...


19

The suggested solution is to run the service unit as a normal service - have a look at the [Install] section. So everything has to be thought reverse, dependencies too. Because the shutdown order is the reverse startup order. That's why the script has to be placed in ExecStop. The following solution is working for me: [Unit] Description=... [Service] Type=...


18

Depending on your distro use the chkconfig or update-rc.d tool to enable/disable system services. On a redhat/suse/mandrake style system: sudo chkconfig apache2 off On Debian: sudo update-rc.d -f apache2 remove Checkout their man pages for more info.


18

halt instructs the hardware to stop all CPU functions, but leaves it in a powered-on state. This usually means someone has to reboot or shut the machine down manually by pressing the power button afterwards. The specific way to achieve this is architecture specific, but for instance the x86 instruction set provides the HLT instructions which halts the ...


16

You can run shutdown -c to cancel an already running shutdown.


16

Only root privileged programs can gracefully shutdown a system. So when a system shuts down in a normal way, it is either a user with root privileges or an acpi script. In both cases you can find out by checking the logs. An acpi shutdown can be caused by power button press, overheating or low battery (laptop). I forgot the third reason, UPS software when ...


15

We don't necessarily need them both, but we have them both because of the history of Unix, and its multiplicity of versions. From their respective man pages: The shutdown utility appeared in 4.0BSD. A reboot utility appeared in Version 6 AT&T UNIX. shutdown is more general-purpose, and more powerful, while reboot is friendlier and easier to remember....


15

The binary shutdown itself checks if your UID is 0. See the strace output of: strace /sbin/shutdown -r -h now ... ... geteuid() = 10001 setuid(10001) = 0 getuid() = 10001 write(2, "shutdown: Need to be root\n", 26shutdown: Need to be root ) = 26 exit_group(1) ...


14

They're not the same thing, just very closely related. In practice, unless you want to specify a particular time to shutdown or to force an immediate unclean reboot/halt/poweroff, it really doesn't matter whether you run shutdown -h or halt... or shutdown -r vs reboot. Things weren't so nicely convenient in the past, but this is the way it works now (a lot ...


13

If your system uses PAM, the login denial when /etc/nologin exists is triggered by the pam_nologin module. You can skip the pam_nologin invocation for users matching certain criteria with pam_succeed_if. For example, if you want to allow users in the adm group to log in on a text console even if /etc/nologin exists, add the following line to /etc/pam.d/...


12

On most Linux systems, the Ctrl+Alt+Del key sequence action is configured in either /etc/inittab or /etc/init/control-alt-delete.conf. Usually, this will reboot the system, but you could modify the command to halt the system instead. In /etc/inittab: ca::ctrlaltdel:/sbin/shutdown -t3 -h now Or /etc/init/control-alt-delete.conf: start on control-alt-...


12

You can suspend or hibernate your system and then automatically wake it up with rtcwake command. For example to suspend (to ram) and resume in 60 seconds do rtcwake -s 60 -m mem To hibernate (suspend to disk) in one hour from now and resume in two hours: sleep 3600; rtcwake -s 3600 -m disk You can also wakeup the system at given time with -t option ...


11

If you are fast enough you can issue an init 2 (or whatever runlevel you want) and that will likely stop the shutdown. Anything involving killing the shutdown command will fail as the command runs too quickly I tried this with the script below and and even it's not fast enough to stop the shutdown #!/bin/bash shutdown -h now shutdown -c "Aborting ...


11

There seems to be no way to log this data to a file. For the boot process, there is the bootlogd package which creates the file /var/log/boot, but nothing for the shutdown/reboot process. As far as I can see there is no way to log with rsyslog either, and even if there was, there are messages printed after rsyslog is stopped. Part of my shutdown/reboot ...


11

Try Molly guard: $ sudo apt-get install molly-guard This package will prevent unintended shutdown/reboot/suspend/hibernate by interactively prompting you to enter the hostname of the system. However, it's trivial to configure molly-guard to completely disable shutdown/reboot/suspend/hibernate. Simply create an executable file at /etc/molly-guard/run.d/99-...


10

Every process has a directory named according to its process id (pid) in the proc filesystem. Therefore you can wait for a specific process' termination by checking whether its directory exists repeatedly. You can use this to perform a system shutdown after process termination like this (replace 2296 by the pid to wait for): su -c 'while [[ -d /proc/2296 ]]...


10

Michael's answer correctly discusses system function when using the hardware power switch, but most desktop environments actually use dbus for this purpose rather than doing it themselves. For example, GNOME uses dbus's org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown when the shutdown button is clicked. When this is sent, dbus does some checks to ...



Only top voted, non community-wiki answers of a minimum length are eligible