Linux让普通用户也能执行shutdown

以Fedora5为例,其它诸如Ubuntu之类也类似。

        当前用户名为:test,为一普通用户。在输入关机命令会出现must be superuser,需要超级用户来执行此命令。操作如下:

[test@localhost ~]$ halt
halt: must be superuser.

经测试本人发现,可以使用umask命令来设置,如下:

[test@localhost ~]$ su -
Password:
[root@localhost ~]# which halt
/sbin/halt
[root@localhost ~]# ll /sbin/halt
 -rwxr-xr-x 1 root root 12584 Feb 14  2006 /sbin/halt
[root@localhost ~]# chmod 4755 /sbin/halt

[root@localhost ~]# ll /sbin/halt
 -rwsr-xr-x 1 root root 12584 Feb 14  2006 /sbin/halt

[root@localhost ~]# exit

[test@localhost ~]$ 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 命令就不同了,普通用户执行它时,系统反馈为:“没有找到相关命令”,意思是你找不到我,当然更没有执行我的权限。

[test@localhost ~]$ shutdown
-bash: shutdown: command not found
针对这个问题,又该如何解决呢?呵呵。

[test@localhost ~]$ su -
Password:
[root@localhost ~]# chmod 0755 /sbin/shutdown
[root@localhost ~]# which shutdown
/sbin/shutdown
[root@localhost ~]# ll /sbin/shutdown
-rwxr-xr-x 1 root root 21872 Feb 14  2006 /sbin/shutdown
[root@localhost ~]# chmod 4755 /sbin/shutdown
[root@localhost ~]# ll /sbin/shutdown
-rwsr-xr-x 1 root root 21872 Feb 14  2006 /sbin/shutdown

修改完成后尝试执行如下:

[test@localhost ~]$ shutdown -h now
-bash: shutdown: command not found
还是不行!?

 通过命令echo $PATH 发现里面有没有/sbin这个路径,所以如果执行shutdown命令可以直接输入绝对路径。如下:

[test@localhost ~]$ /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!

【完】



本文转自tiancong 51CTO博客,原文链接:http://blog.51cto.com/tiancong/655866

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值