How do I make a User login shutdown my box?

Stuart Halliday StuartH at ecs-tech.com
Mon Sep 27 11:53:12 UTC 2004


> How about using sudo.  Write a simple shell script to call sudo shutdown 
> then grant the sleep user access to this command with the NOPASSWD option
> in the sudoers file.

Thanks Stuart that did it. Much appreciated.
I'd never heard of sudo before.

To help others who may also enquire in the future, here is what I did.

I altered the /etc/passwd file so that the bash shell would be run when this user 'sleep' logs in.

I gave the user 'sleep' in /etc/sudoers permission to run the poweroff command with no password.

and I added the line in .bashrc:

sudo /sbin/poweroff -i

So now if I login to the box or via a external telnet connection it will shutdown the box. Nice and simple!

I needed this because at times we need to power down the office for Mains voltage testing and this ability allows any manager the ability to switch off the Linux box safely. 

I'll of course change the password each time it's used to keep it secure though! Password is kept in the safe.... ;-)





More information about the redhat-list mailing list