Standard permissions do not allow regular users to shutdown a unix machine. Often it is useful to grant non-super users the ability to shutdown the server. there are a number of ways to do this. This is one.
Requirements[]
- Access to the root account
Method 1 (recommended)[]
This method uses sudo to allow a user to run shutdown as root.
- Login as root
- Add user to group, wheel, in /etc/group
- nonsense deleted, never change permissions of /etc/sudoers"
- Edit /etc/sudoers using "sudo visudo"
- Add line:
- %wheel ALL= NOPASSWD: /sbin/shutdown
- Add line:
- nonsense deleted
- Any user in group wheel, can shutdown computer by executing:
- sudo /sbin/shutdown ...
- Optional:
- Add an alias for shutdown to have sudo
- alias shutdown='sudo /sbin/shutdown'
- Add an alias for shutdown to have sudo
Method 2[]
- Login or switch users to root
- you can switch users to root by typing su at a command prompt.
- Edit /etc/groups
- add a line for group shutdown and add your user name to it
- Example: shutdown:x:510:yourUserName
- Execute: groups to display you group membership
- Change ownership of /sbin/shutdown giving access to group shutdown
- Execute: chown root:shutdown /sbin/shutdown
- ls -l /sbin/shutdown should display similar to the following
- ... root shutdown 19K Jan 23 10:50 /sbin/shutdown
- Change permissions to allow the shutdown group read and execute permission.
- Execute: chmod 750 /sbin/shutdown
- ls -l /sbin/shutdown should display similar to the following
- -rwxr-x--- 1 root shutdown 19K Jan 23 10:50 /sbin/shutdown
- shutdown can only be run by root so you need to have group shutdown execute the program as if you were root.
- Execute chmod u+s /sbin/shutdown
- ls -l /sbin/shutdown should display similar to the following
- -rwsr-x--- 1 root shutdown 19K Jan 23 10:50 /sbin/shutdown
- To test execute: shutdown -k now and shutdown will pretend to shutdown.
- To shutdown, execute shutdown -h now. For Details on this command, execute shutdown --help
Common Errors[]
- bash: /sbin/shutdown: Permission denied
- This means that shutdown does not allow your user or group to execute the file. try ls -l /sbin/shutdown, see howto change file permissions
- shutdown: you must be root to do that!
- shutdown will not 'shutdown' without being root is some form of 'sudo' or 'chmod +s'
- /etc/shutdown.allow, seems to only be used in inittab, and shutdown -a now does not work from terminal.