Linux系统精讲---2.0suid特殊权限

回复 收藏

icon_txt.gif2.0_所属主特殊权限set_uid_suid_.pdf

#useradd aming

#which passwd 【检查可执行命令passwd的路径】

/usr/bin/passwd

#ls -l /usr/bin/passwd 【此处第一目录是usr,不是user。】

-rwsr-xr-x. 1 root root 25980 2月  22 2012 /usr/bin/passwd        【此处user的权限不再是rwx,而是rws】

【s表示:当其他用户执行该命令的时候,赋予该用户临时root权限,==set_uid == suid】

例子:

#ls -l /root 【root用户下,执行ls命令,列出root目录列表】

-rw-r--r--. 1 root root     4 1月   2 05:27 1.txt

-rw-------. 1 root root  1305 12月 30 02:46 anaconda-ks.cfg

-rw-r--r--. 1 root root 23851 12月 30 02:46 install.log

-rw-r--r--. 1 root root  5775 12月 30 02:45 install.log.syslog

#su - aming 【切换至aming用户】

$ls -l /root   【在aming用户下,执行ls命令】

ls: 无法打开目录/root/: 权限不够  【该用户没有使用ls命令的权限】

$exit   【在aming用户线,退出到root用户,logout也可以】

#ls -l /bin/ls

-rwxr-xr-x. 1 root root 112664 11月 22 2013 /bin/ls

#chmod u+s /bin/ls 【给ls命令增加s特殊权限】

#ls -l /bin/ls

-rwsr-xr-x. 1 root root 112664 11月 22 2013 /bin/ls 【此时ls命令user的权限是rws】

#su - aming 【再次切换到aming用户】

$ls -l /root 【在aming用户下,使用ls命令】

-rw-r--r--. 1 root root     4 1月   2 05:27 1.txt

-rw-------. 1 root root  1305 12月 30 02:46 anaconda-ks.cfg

-rw-r--r--. 1 root root 23851 12月 30 02:46 install.log

-rw-r--r--. 1 root root  5775 12月 30 02:45 install.log.syslog

#chmod u-x /bin/ls 【去掉ls命令的可执行权限】

#ls -l /bin/ls

-rwSr-xr-x. 1 root root 112664 11月 22 2013 /bin/ls 【user权限里面的rws变成了大写S】

#ls -l /root 【root用户,执行ls命令,S没有影响】

-rw-r--r--. 1 root root     4 1月   2 05:27 1.txt

-rw-------. 1 root root  1305 12月 30 02:46 anaconda-ks.cfg

-rw-r--r--. 1 root root 23851 12月 30 02:46 install.log

-rw-r--r--. 1 root root  5775 12月 30 02:45 install.log.syslog

#su - aming

$ls -l /root  【此时仍可以执行,是因为其user权限去掉了s,但是others的权限,仍然有x可执行权限】

-rw-r--r--. 1 root root     4 1月   2 05:27 1.txt

-rw-------. 1 root root  1305 12月 30 02:46 anaconda-ks.cfg

-rw-r--r--. 1 root root 23851 12月 30 02:46 install.log

-rw-r--r--. 1 root root  5775 12月 30 02:45 install.log.syslog

$exit

#chmod o-x /bin/ls 【去掉others的可执行权限】

#su - aming

$ls -l /root 【aming用户下,执行ls命令】

-bash: /bin/ls: 权限不够

NOTE:

set uid 只能作用于可执行的二进制文件

拓展

当有特殊权限时,当用数字表示user/group/others的权限时,是四个数字表达。

传统表达为755,766等。

#ls -l /usr/bin/passwd

-rwsr-xr-x. 1 root root 25980 2月  22 2012 /usr/bin/passwd

此处users的权限时rws,表达式为 4755

第一位数字规定:

user    group    others    数字    

-    -    -    0    

-    -    t    1    

-    s    -    2    

-    s    t    3    

s    -    -    4    

s    -    t    5    

s    s    -    6    

s    s    t    7    

2017-01-06 01:24 举报
已邀请:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: