How to: Allow Any User To Shutdown a Linux Server

by on February 23, 2006 · 9 comments· Last updated December 28, 2009

You need to use the sudo command to grant a permission to other users to shutdown your server. The sudo command allows a permitted user to execute a command as the superuser or another user, as specified in the /etc/sudoers file. Login as a root user and type the visudo command to edit the sudoers file.

Use Configuration

In this example, allow user rocky to shutdown computer (first login as a root user):
$ su -
# visudo

Append the following configuration to a file:
rocky server.example.com=/sbin/halt /sbin/reboot
Save file and close the file. Now, rocky user can halt server by typing the following command:
$ sudo /sbin/halt
Output:

Password:

Please note that at password prompt rocky need to type his own password.

Another option is add users to /etc/shutdown.allow access control file. shutdown command can see if an authorized user is logged in on one of the virtual consoles. If shutdown command is called with the -a argument , it checks to see if the file /etc/shutdown.allow is present. It then compares the login names in that file with the list of people that are logged in on a virtual console only if one of those authorized users or root is logged in, it will proceed. Otherwise, it will write the message

shutdown: no authorized users logged in

First login as a root user:
# echo rocky >> /etc/shutdown.allow
Alternatively, use a text editor such as vi to add a username to etc/shutdown.allow file (max 32 names are allowed at a time):
# vi /etc/shutdown.allow
Finally, rocky can login and type the following command:
rocky@server1 $ /sbin/shutdown -a -h 0

See also:



You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 9 comments… read them below or add one }

1 we3cares September 15, 2008 at 4:15 am

Very Great Article….. Like it so Much..

Reply

2 Philippe December 26, 2009 at 3:11 pm

Nice topic.

But in :
# touch /etc/shutdown.allow
# echo”username” >> /etc/shutdown.allow

The first line is useless. (touch)

Reply

3 Vivek Gite December 28, 2009 at 2:53 pm

Once again thanks for pointing it out :)

Reply

4 Philippe December 28, 2009 at 4:50 pm

Yep – but then you typed it too quickly

echo”rokcy” >> /etc/shutdown.allow

should read

echo “rocky” >> /etc/shutdown.allow

and by the way, these quotes are useless here. I’ve never seen a user login that would require quoting, BTW.

echo rocky >> /etc/shutdown.allow

Reply

5 Vivek Gite December 28, 2009 at 5:15 pm

My bad :(

Reply

6 Philippe December 28, 2009 at 5:20 pm

Well I share the easy part.

But again,
You still mispelled it – that’s r-o-c-k-y
not r-o—k—c—-y

breeze deeply. ;-))

Reply

7 Vivek Gite December 28, 2009 at 5:47 pm

I’m embarrassed to say that it took me forever to realize a typo :(

Reply

8 Parag July 29, 2010 at 4:26 am

That’s great info. It works and thanks a lot.

Reply

9 mclien June 4, 2012 at 9:03 am

at least in debian systems the shutdoen.allow only works for the alt+ctrl+del way of it.
still the user isn’t allowed to invoke /sbin/shutdown…

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 14 + 5 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Tagged as: , , , , , ,

Previous post:

Next post: