Become root and at the prompt type:
visudo
This brings up a 'vi' session in which you can edit /etc/sudoers file. It is the most common way of editing your sudoers file. There may be other ways using different editors, but your system must be configured for it separately. visudo works like vipw, which similarly allows you to edit your password or group files without corrupting them.
The layout of sudoers file is fairly straight forward. Command syntax is:
username host = command
For example, I like to be able to run traceroute and tcpdump without having to log in as root. So I have the following in my sudoers file:
# Cmnd alias specification Cmnd_Alias TRACEROUTE = /usr/sbin/traceroute Cmnd_Alias TCPDUMP = /usr/sbin/tcpdump
# User privilege specification kevin ALL = TCPDUMP, TRACEROUTE
So in the above case, kevin can run the programs tcpdump and traceroute.
In your case for halt, I would make the following entries:
Cmnd_Alias HALT = /sbin/halt niki ALL = HALT
If I were your system admin I'd probably change the keyword ALL in your line to the name of your machine. That way you'd only be able to halt your own machine, and not others on the network where this sudoers file had been propagated. If you're doing this just for your own use on your own box at home, then just use ALL to keep it simple.
Note that when you specify the name of the program that gets sudo status, you need to give it the full directory path as I've done above.
Once you've set up your sudoers, you can start using it. Example (as a regular user, not root):
sudo traceroute yahoo.com
It will next query me for Password: I give it my user password, not root password. And that's about it.
As a user you can check to see what commands are available to you as a sudo user by issuing the command
sudo -l // that's an ell, not a one
Here's mine:
kevin@sakura:~/tmp$ sudo -l User kevin may run the following commands on this host:
(root) /usr/sbin/tcpdump (root) /usr/bin/ethereal (root) /usr/bin/tethereal (root) /usr/sbin/arp (root) /sbin/ifconfig (root) /usr/sbin/traceroute (root) /usr/bin/nmap (root) /usr/bin/apt-get (root) /usr/bin/dpkg (root) /usr/sbin/ettercap (root) /usr/sbin/synaptic
And here's my complete /etc/sudoers file: (mind the wordwrap, which is not permitted in the sudoers file)
# sudoers file. # # This file MUST be edited with the 'visudo' command as root. # See the man page for details on how to write a sudoers file.
# Host alias specification
# User alias specification
# Cmnd alias specification Cmnd_Alias TCPDUMP = /usr/sbin/tcpdump Cmnd_Alias ETHEREAL = /usr/bin/ethereal Cmnd_Alias TETHEREAL = /usr/bin/tethereal Cmnd_Alias ARP = /usr/sbin/arp Cmnd_Alias IFCONFIG = /sbin/ifconfig Cmnd_Alias TRACEROUTE = /usr/sbin/traceroute Cmnd_Alias NMAP = /usr/bin/nmap Cmnd_Alias APTGET = /usr/bin/apt-get Cmnd_Alias DPKG = /usr/bin/dpkg Cmnd_Alias ETTERCAP = /usr/sbin/ettercap Cmnd_Alias SYNAPTIC = /usr/sbin/synaptic
# User privilege specification root ALL = (root) ALL kosuke ALL = TCPDUMP, ETHEREAL, ARP, IFCONFIG, TRACEROUTE, NMAP, APTGET, DPKG, ETTERCAP kevin ALL = TCPDUMP, ETHEREAL, TETHEREAL, ARP, IFCONFIG, TRACEROUTE, NMAP, APTGET, DPKG, ETTERCAP, SYNAPTIC
# end sudoers