Linux下普通用户执行shutdown

简介:

题注:总会有一种感觉,很多的困惑会在网络上的某个角落得以解决,于是心情也会变得舒畅起来,我希望本文也可以带给你这种感觉。

本文的原址[我的百度博客]:http://hi.baidu.com/oldfile/blog/item/3d34c4963616b353d1135e1c.html

现在对其进行了Ubuntu系统的普通用户关机实现,试了以后才知道与Fedora不略有不同。

[Fedora5实现]

当前用户名为: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!

[Ubuntu11.10]

参考上面的Fedora更改的过程,对/sbin/shutdown的权限进行更改,会提示更改失败,如下:

shenzhi@sz08254:~$ sudo chmod 4755 /sbin/shutdown 
sudo: unable to resolve host sz08254
解决办法是登录超级用户进行操作,在Ubuntu中超级用户是没有密码的,也是不可以直接拿来用,若想使用必须先设置密码,如下:
shenzhi@sz08254:~$ sudo passwd
sudo: unable to resolve host sz08254
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

登录到超级用户:
shenzhi@sz08254:~$ su -
Password: 

查找shutdown所在路径:
root@sz08254:~# which shutdown
/sbin/shutdown

查看shutdown文件的权限:
root@sz08254:~# ll /sbin/shutdown 
-rwsr-xr-x 1 root root 67360 2011-10-27 13:14 /sbin/shutdown*

更改shutdown的权限:
root@sz08254:~# chmod 4755 /sbin/shutdown

退出超级用户:

root@sz08254:~# exit
logout

使用普通用户实施关机:
shenzhi@sz08254:~$ shutdown -h now
shenzhi@sz08254:~$ 
Broadcast message from shenzhi@sz08254
    (/dev/pts/0) at 10:42 ...

The system is going down for halt NOW!
Connection to 192.168.0.50 closed by remote host.
Connection to 192.168.0.50 closed.
【完】



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

相关文章
|
3月前
|
Shell Linux Perl
将 Linux 系统中 UID 大于等于 1000 的普通用户都删除shell脚本
将 Linux 系统中 UID 大于等于 1000 的普通用户都删除shell脚本
41 1
|
3月前
|
Linux
百度搜索:蓝易云【Linux命令之shutdown详解】
这些是shutdown命令的一些常见用法和选项。请注意,在执行关机或重启操作之前,请确保您具有足够的权限,并通知系统上的用户进行适当的操作。谨慎使用强制选项,以避免数据丢失或系统损坏。
55 1
|
4月前
|
Ubuntu Linux Windows
linux(三十七)远程管理命令reboot和shutdown
linux(三十七)远程管理命令reboot和shutdown
60 0
|
4月前
|
Linux 虚拟化
Linux命令(35)之shutdown
Linux命令(35)之shutdown
124 1
|
6月前
49Linux - 系统管理(关机重启:reboot、shutdown、init)
49Linux - 系统管理(关机重启:reboot、shutdown、init)
21 0
|
3月前
|
Linux 数据安全/隐私保护
Linux中普通用户使用sudo命令提示lin is not in the sudoers file. This incident will be reported.
Linux中普通用户使用sudo命令提示lin is not in the sudoers file. This incident will be reported.
|
1月前
|
网络协议 Linux API
Linux网络编程:shutdown() 与 close() 函数详解:剖析 shutdown()、close() 函数的实现原理、参数说明和使用技巧
Linux网络编程:shutdown() 与 close() 函数详解:剖析 shutdown()、close() 函数的实现原理、参数说明和使用技巧
74 0
|
1月前
|
Shell Linux C语言
【Shell 命令集合 系统管理 】⭐⭐⭐Linux 关机 shutdown命令 使用指南
【Shell 命令集合 系统管理 】⭐⭐⭐Linux 关机 shutdown命令 使用指南
28 0
|
6月前
|
Linux Shell 开发工具
【Linux】创建普通用户以及Linux问题解决
创建普通用户 ❓可以看到我们现在是一个root用户,并不是一个普通用户,我们要如何创建普通用户呢?
80 0
|
10月前
|
安全 Linux
Linux系统中普通用户获取root权限
Linux系统中普通用户获取root权限
606 0