日期:2014-05-16  浏览次数:20644 次

关于root组的问题
本人是centOS6.2,系统只有一普通用户yan,执行fdisk -l时无法显示数据,如下:
[yan@localhost ~]$ fdisk -l
[yan@localhost ~]$

但是使用root却可以:
[root@localhost yan]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c0343

  Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1332 10485760 83 Linux
/dev/sda3 1332 1593 2097152 82 Linux swap / Solaris
/dev/sda4 1593 2611 8182784 5 Extended
/dev/sda5 1593 2611 8181760 83 Linux

查看fdisk的权限取下:
-rwxr-xr-x. 1 root root 111404 Dec 8 2011 /sbin/fdisk

问题1:上面权限中其他用户拥有执行权限,为什么用户yan执行结果什么都没有呢?


现在想让yan也能有执行结果,所以想办法让yan能正确执行该命令(sudo我知道可以,先使用其他方法试试看)
因为/sbin/fdisk是属于root组的,root组有执行权限,所以将yan加入root组应该就能正确执行fdisk命令,
使用gpasswd命令执行如下:
[root@localhost yan]# gpasswd -a yan root
Adding user yan to group root

然后groups以下:
[root@localhost yan]# groups
root bin daemon sys adm disk wheel yan
已经将yan加入到root组,在使用yan执行fdisk命令,
[yan@localhost ~]$ fdisk -l
[yan@localhost ~]$
还是没有结果
问题2:请问上面是什么原因,已经加入了root组了去不能执行root命令。

请各位帮忙解答下,万分感谢。





------解决方案--------------------
$ fdisk -l
这样子,普通用户是有执行权限的,否则会提示permission deny的信息。

没有显示信息,估计是fidsk程序本身的设定,用getuid检测到不是root,就不会显示或者获取硬盘信息。

后面,加入root用户组也是不行的,类似的。一定要检测到getuid的值是root,估计才可以。
------解决方案--------------------
很明显是因为yan用户执行fdisk程序的时候fdisk进程的有效用户ID非root,导致没有权限读取一个形如这样的磁盘记录文件引起的:

rw- rw- --- root root fdisk_infomation.txt