以Fedora5為例,其它諸如Ubuntu之類也類似。
目前使用者名為:test,為一普通使用者。在輸入關機指令會出現must be superuser,需要超級使用者來執行此指令。操作如下:
[[email protected] ~]$ halt
halt: must be superuser.
經測試本人發現,可以使用umask指令來設定,如下:
[[email protected] ~]$ su -
Password:
[[email protected] ~]# which halt
/sbin/halt
[[email protected] ~]# ll /sbin/halt
-rwxr-xr-x 1 root root 12584 Feb 14 2006 /sbin/halt
[[email protected] ~]#chmod 4755 /sbin/halt
[[email protected] ~]#ll /sbin/halt
-rwsr-xr-x 1 root root 12584 Feb 14 2006 /sbin/halt
[[email protected] ~]#exit
[[email protected] ~]$halt
Broadcast message from root (pts/1) (Thu May 19 12:25:35 2011):
The system is going down for system halt NOW!
比較一下就會發現,當普通使用者執行halt指令時,系統回報說“需要超級使用者來執行”,意思是可以找到我,但是你沒有執行我的權限。
而shutdown 指令就不同了,普通使用者執行它時,系統回報為:“沒有找到相關指令”,意思是你找不到我,當然更沒有執行我的權限。
[[email protected] ~]$ shutdown
-bash: shutdown: command not found針對這個問題,又該如何解決呢?呵呵。
[[email protected] ~]$ su -Password:
[[email protected] ~]# chmod 0755 /sbin/shutdown
[[email protected] ~]# which shutdown
/sbin/shutdown
[[email protected] ~]# ll /sbin/shutdown
-rwxr-xr-x 1 root root 21872 Feb 14 2006 /sbin/shutdown
[[email protected] ~]# chmod 4755 /sbin/shutdown
[[email protected] ~]# ll /sbin/shutdown
-rwsr-xr-x 1 root root 21872 Feb 14 2006 /sbin/shutdown
修改完成後嘗試執行如下:
[[email protected] ~]$ shutdown -h now
-bash: shutdown: command not found
還是不行!?
通過指令echo $PATH 發現裡面有沒有/sbin這個路徑,是以如果執行shutdown指令可以直接輸入絕對路徑。如下:
[[email protected] ~]$/sbin/shutdown -h now
Broadcast message from root (pts/1) (Thu May 19 12:56:09 2011):
The system is going down for system halt NOW!
【完】