说明:
拥有s权限的命令(文件) : 为了确保非所有者用户 , 在使用该命令时,临时拥有所有者的身份 ; 给一个文件设置set_uid特殊权限,前提是该文件是一个可执行的二进制文件(一般都是给命令加上这样的特殊权限) , 否则没有任何意义 .
例如:
查看设置了set_uid,s权限的passwd 命令:
[root@centos7-01 ~]# which passwd
/usr/bin/passwd
[root@centos7-01 ~]# which passwd | xargs ls -l
-rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd
[root@centos7-01 ~]#
如何设置set_uid:
方式一:
[root@centos7-01 ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@centos7-01 ~]# ls -l /usr/bin/ls
-rwxr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
[root@centos7-01 ~]# chmod u+s !$
chmod u+s /usr/bin/ls
[root@centos7-01 ~]# !ls
ls -l /usr/bin/ls
-rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
[root@centos7-01 ~]#
方式二:
[root@centos7-01 ~]# echo !$
echo /usr/bin/ls
/usr/bin/ls
[root@centos7-01 ~]# chmod u=rws !$
chmod u=rws /usr/bin/ls
[root@centos7-01 ~]# ls -l !$
ls -l /usr/bin/ls
-rwSr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls 【注意这里就是在u=rws 未添加x所以显示为S,权限其实已经可以使用了】
[root@centos7-01 ~]#
应该补上如下操作:
[root@centos7-01 ~]# chmod u+x /usr/bin/ls
[root@centos7-01 ~]# ls -l !$
ls -l /usr/bin/ls
-rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
[root@centos7-01 ~]#
或者直接一次性写完:
[root@centos7-01 ~]# chmod u=rwsx !$
chmod u=rwsx /usr/bin/ls
[root@centos7-01 ~]# ls -l !$
ls -l /usr/bin/ls
-rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
[root@centos7-01 ~]#
查看未设置set_uid与设置set_uid区别:
[root@centos7-01 ~]# useradd huangxin
[root@centos7-01 ~]# su - huangxin
[huangxin@centos7-01 ~]$ ls /root/
ls: 无法打开目录/root/: 权限不够
[huangxin@centos7-01 ~]$ chmod u+s !ls:2
-bash: :2: bad word specifier
[huangxin@centos7-01 ~]$ chmod u+s !$ls:2
chmod u+s /root/ls:2
chmod: 无法访问"/root/ls:2": 权限不够
[huangxin@centos7-01 ~]$ su - root
密码:
上一次登录:四 6月 7 22:34:23 CST 2018从 192.168.85.1pts/0 上
[root@centos7-01 ~]#
[root@centos7-01 ~]# chmod u+s !$ls:2
chmod u+s huanxinls:2
chmod: 无法访问"huanxinls:2": 没有那个文件或目录
[root@centos7-01 ~]# chmod u+s /usr/bin/ls
[root@centos7-01 ~]# ls -l !$
ls -l /usr/bin/ls
-rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
[root@centos7-01 ~]# su huangxin
[huangxin@centos7-01 root]$ ls /root/
anaconda-ks.cfg
[huangxin@centos7-01 root]$