天天看点

Linux系统普通用户可以执行,Linux让普通用户也能执行shutdown

以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!

【完】