针对可执行的二进制文件,保证普通用户在执行命令时,能够临时得到root权限。例如passwd命令临时得到root权限来更改密码。windows
[root@centos01 ~]# which passwd /usr/bin/passwd [root@centos01 ~]# ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd [root@centos01 ~]# ls -l /etc/shadow # 查看密码文件 ----------. 1 root root 610 9月 15 17:45 /etc/shadow [root@centos01 ~]# ls -l /usr/bin/ls -rwxr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls [root@centos01 ~]# chmod u+s /usr/bin/ls # 给二进制命令文件添加set uid权限 [root@centos01 ~]# ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls [root@centos01 ~]# chmod u=rws /usr/bin/ls [root@centos01 ~]# ls -l /usr/bin/ls -rwSr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls # S(大写s) 由于当前全部者没有执行权限(x)
用在可执行性二进制文件或者目录上。看成用在二进制文件时,会在执行阶段拥有所属组的权限;看成用于目录时,任何用户在该目录下建立的文件或子目录都具备和该目录相同的所属组。centos
[root@centos01 ~]# mkdir d0917 [root@centos01 ~]# ls -ld d0917/ drwxr-xr-x. 2 root root 6 9月 18 05:42 d0917/ [root@centos01 ~]# chmod g+s d0917/ [root@centos01 ~]# !ls ls -ld d0917/ drwxr-sr-x. 2 root root 6 9月 18 05:42 d0917/ [root@centos01 ~]# chown :test01 d0917/ [root@centos01 ~]# touch d0917/f01.txt [root@centos01 ~]# ls d0917/f01.txt -l -rw-r--r--. 1 root test01 0 9月 18 05:44 d0917/f01.txt # 所属组为test01 [root@centos01 ~]# [root@centos01 ~]# chmod g-s d0917/ # 去掉set gid权限 [root@centos01 ~]# touch d0917/f02.txt [root@centos01 ~]# ls d0917/f02.txt d0917/f02.txt [root@centos01 ~]# ls d0917/f02.txt -l -rw-r--r--. 1 root root 0 9月 18 05:45 d0917/f02.txt # 恢复到原来的所属组 [root@centos01 ~]# ls -l d0917/ 总用量 0 -rw-r--r--. 1 root test01 0 9月 18 05:44 f01.txt -rw-r--r--. 1 root root 0 9月 18 05:45 f02.txt [root@centos01 ~]# ls -ld d0917/ drwxr-xr-x. 2 root test01 34 9月 18 05:45 d0917/ [root@centos01 ~]# mkdir d0917/sd01 [root@centos01 ~]# ls -ld d0917/sd01 drwxr-xr-x. 2 root root 6 9月 18 05:46 d0917/sd01
防删除权限位。
要删除一个文件,要看的是文件所在的目录有没有写权限,而不是看删除的文件自己有没有权限。(root权限用户能够删除)ui
[root@centos01 ~]# ls /tmp/ -ld drwxrwxrwt. 8 root root 4096 9月 18 05:38 /tmp/ # 其中权限位上其余用户的权限中有个t,就表示了stick bit权限。 # 用户能够在含有stick bit权限的目录下建立文件,但不能删除该目录下的文件。
相似于windows系统中的快捷方式;
命令为: ln -s 源文件(实体文件) 软链接文件
作软链接尽可能使用绝对路径,由于若是是相对路径,更改软链接文件时,对应的链接文件可能找不到。
code
硬链接只支持对文件链接;
不能跨分区作硬链接。 命令为: ln 源文件(实体文件) 硬链接文件blog
软链接不能够删除源文件(删除后就没有了),而硬链接能够删除源文件,经过链接文件也能获得文件内容。it