最新消息:

Linux中root权限下放

Linux ipcpu 8867浏览

一般来说,root权限是在系统管理员手中,不能轻易就给了普通用户,但是有时普通用户想做一些高级一点的操作,又得麻烦系统管理员,比如啊,改个程序文件重启个Apache等等。
于是就有了root权限的下放,使得普通用户能够执行root用户才能执行的命令。
在CentOS中,root权限的下放可以通过/etc/sudoers 文件来实现。
我们打开这个文件。
这个文件的开头就写明了这个文件的用途:
Sudoers allows particular users to run various commands as the root user, without needing the root password.
在文件的最底部给出了使用的格式。
## Allows people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL
## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
这里有四个部分,第一个%wheel表示的是用户组,第二个部分ALL是作用对象,也就是在哪个主机上有效, 第三部分是以谁的身份来运行,第四个部分就是要执行的命令了。
举个例子:我们要允许www组的用户拥有重启apache的权利,我们就可以在这个文件底部添加:
%www? ALL=(root)? /usr/sbin/apachectl -k start
www? ALL=(root)? /usr/sbin/apachectl -k restart
注意:加上%指定的是用户组,不加%指定的是用户。执行命令这里一定要写完整路径,毕竟每个用户的环境变量都不一样。
然后保存,注意一定要强制保存,加上叹号。
我们切换到www用户
[ipcpu@s104 ~]$ sudo /usr/sbin/apachectl -k start
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
Password:
[ipcpu@s104 ~]$ netstat -tunlp | grep 80
(No info could be read for "-p": geteuid()=500 but you should be root.)
tcp        0      0 :::80                       :::*                        LISTEN      -
[ipcpu@s104 ~]$
后记:这个配置文件的中间部分给出了许多Alias,包括Host_Alias,设定主机的,User_Alias 设定用户的,Cmnd_Alias设定相关命令的,大家可以自己探索一下喔。

转载请注明:IPCPU-网络之路 » Linux中root权限下放