How To Wiki
Advertisement

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.

  1. Login as root
  2. Add user to group, wheel, in /etc/group
  3. nonsense deleted, never change permissions of /etc/sudoers"
  4. Edit /etc/sudoers using "sudo visudo"
    • Add line:
      %wheel ALL= NOPASSWD: /sbin/shutdown
  5. 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'

Method 2[]

  1. Login or switch users to root
    you can switch users to root by typing su at a command prompt.
  2. 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
  3. 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
  4. 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
  5. 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
  6. To test execute: shutdown -k now and shutdown will pretend to shutdown.
  7. 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.


    From HowTo Wiki, a Wikia wiki.
Advertisement