Let a common user shutdown and reboot
From Gentoo Linux Wiki
| Installation • Kernel & Hardware • Networks • Portage • Software • System • X Server • Gaming • Non-x86 • Emulators • Misc |
[edit] Introduction
The aim of this tutorial is to allow a common user to shutdown or reboot his/her own machine. This tutorial is not intended to those who use a login manager (such as GDM, KDM and XDM) but instead to those who prefer the console.
First we have to install sudo:
- emerge -av app-admin/sudo
Now we have to edit its configuration file. We can easily do this running visudo - it will launch an editor specified in the EDITOR environment variable, and prevent /etc/sudoers from damage by concurrent edits. Add the following lines to your /etc/sudoers. Now you have to add all users you want to allow to shutdown or reboot your machine:
| File: /etc/sudoers |
Substitute "user" with your username: user ALL=(root) NOPASSWD: /sbin/shutdown |
This enables you to shutdown your computer using this command:
sudo /sbin/shutdown -h now
and reboot it using
sudo /sbin/shutdown -r now
You can also create two aliases in the .bashrc:
| File: ~/.bashrc |
alias rb="sudo /sbin/shutdown -r now" alias sd="sudo /sbin/shutdown -h now" |
As an alternative, you can create two scripts that will work independently of your current shell. The content of the shutdown script is:
| File: /sbin/sd |
#!/bin/bash sudo /sbin/shutdown -h now |
The content of the reboot script is:
| File: /sbin/rb |
#!/bin/bash sudo /sbin/shutdown -r now |
Now you need to change the permissions of both scripts:
chmod 744 /sbin/rb /sbin/sd
Whenever you want to shutdown the machine, you just have to type sd and to reboot you can type rb.
