|

楼主 |
发表于 2010-10-28 22:08:55
|
显示全部楼层
Linux 跟 Windows 差異還挺大的, 寫程式外還需懂一些作業系統特性,
不是拿 Windows 那套來照抄就可以 ....
關於如何關機不用 root 密碼, 網路找到兩個方法
How to shutdown and reboot without sudo password?
there are two ways to do that (Any other ways available?)
1. Adding suid mode to /sbin/shutdown
By adding suid mode to shutdown command, you are allowing regular user to run shutdown command as root.
sudo chmod u+s /sbin/shutdown
Now you can run shutdown without needing sudo.
2. Modify /etc/sudoers with visudo
This seems to be proper way to allow a command to run as root from specified users without needing to type password.
sudo visudo
By running visudo, it leads to edit /etc/sudoers.
Adding the line below to that file, assume mysurface is the user that allow to shutdown without password.
mysurface ALL = NOPASSWD: /sbin/shutdown
For ubuntu, usually the default user is in the %admin group. Therefore, you can also allow all users from the %admin group to shutdown without password.
%admin ALL = NOPASSWD: /sbin/shutdown
In fact, you still need sudo to shutdown, but this time you do not need to specified password.
sudo shutdown -h now
You can also reboot the system by using shutdown command too.
sudo shutdown -r now |
|