[root@hf-01 ~]# which passwd
/usr/bin/passwd
[root@hf-01 ~]# ls -l /usr/bin/passwd 会发现passwd文件含有特殊的s权限
-rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd
[root@hf-01 ~]# ls /etc/shadow
/etc/shadow 改用户密码的文件
[root@hf-01 ~]# ls -l !$ 会发现更改密码的文件权限为000
ls -l /etc/shadow
----------. 1 root root 665 10月 26 08:04 /etc/shadow
[root@hf-01 ~]# ls -l /usr/bin/ls 这里想给ls命令加一个
-rwxr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls
然后复制SSH渠道,打开另一个终端2hf(1)下
[root@hf-01 ~]# su - hanfeng 切换到普通用户hanfeng下去
[hanfeng@hf-01 ~]$ whoami 来查看当前用户
hanfeng
[hanfeng@hf-01 ~]$ ls /root/ 这时访问/root/目录,会提示没权限
ls: 无法打开目录/root: 权限不够
这时回到之前的终端下1hf(0)下
[root@hf-01 ~]# chmod u+s /usr/bin/ls 给ls命令增加+s权限
[root@hf-01 ~]# ls -l /usr/bin/ls 这时查看ls命令,会发现x变化为了s权限(小写的s包括了x权限,大写的S表示没有x权限)
-rwsr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls
在切换到另一个终端2hf(1)下
[hanfeng@hf-01 ~]$ ls /root/ 这时会看到有访问权限了,就是因为set_uid权限赋给ls。(当在其他用户下使用ls命令时,在执行过程中会以root身份来运行)
11.txt 123 234 2.txt 33.txt anaconda-ks.cfg.1 ha.txt hf
[hanfeng@hf-01 ~]$ ls -ld /root/
dr-xr-x---. 5 root root 4096 10月 26 09:41 /root/
回到终端1hf(0)下
[root@hf-01 ~]# chmod u-s /usr/bin/ls 去除set_uid赋予给ls的权限
[root@hf-01 ~]# chmod u+s /usr/bin/ls 命令ls被赋予了s权限
[root@hf-01 ~]# chmod u-s /usr/bin/ls 收回s权限
[root@hf-01 ~]# chmod u=rws /usr/bin/ls 这也是赋予ls权限的方法,但是它缺少可执行的权限(小写的s包括了x权限,大写的S表示没有x权限)
[root@hf-01 ~]# !ls 会发现这里显示的是大写S
ls -l /usr/bin/ls
-rwSr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls
[root@hf-01 ~]# chmod u+x /usr/bin/ls 在这里再给它加上+x可执行的权限即可
[root@hf-01 ~]# !ls 会发现这里显示的是小写s
ls -l /usr/bin/ls
-rwsr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls
[root@hf-01 ~]#