该权限针对二进制可执行文件,是普通用户在执行该文件时临时具备该文件全部者的权限 设置该权限的命令为:chmod u+s filename,去掉该权限的命令为chmod u-s filenamewindows
[root@test-01 ~]# ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd [root@test-01 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls [root@test-01 ~]# ls -l /usr/bin/ls -rwxr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls [root@test-01 ~]# chmod u+s /usr/bin/ls [root@test-01 ~]# !ls ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls
[root@test-01 ~]# su lichao [lichao@test-01 root]$ whoami lichao [lichao@test-01 root]$ ls ls: 没法打开目录.: 权限不够 [lichao@test-01 root]$ ls 4 anaconda-ks.cfg
上面两段代码须要穿插着看,一开始没有赋予/use/bin/ls set_uid权限时,普通用户是没法使用这个命令,而后经过执行chmod u+s /usr/bin/ls这条命令使普通用户在执行ls时暂时拥有了root的权限,因此可以执行。ui
set gid 属性能够做用在二进制可执行文件上,也能够做用在目录上。看成用在可执行文件上时跟set uid 做用相似,它会使普通用户在执行这个文件时具备文件所属组的权限。目录被设置这个属性后,任何用户在这个目录下建立的文件都具备和该目录所属组相同的组。code
[root@test-01 tmp]# chmod g+s /tmp/1 [lichao@test-01 tmp]$ touch /tmp/1.txt [lichao@test-01 tmp]$ touch /tmp/1/2.txt [lichao@test-01 tmp]$ ls -l /tmp 总用量 4 drwxr-srwx. 3 root root 4096 12月 23 07:20 1 -rw-rw-r--. 1 lichao lichao 0 12月 23 07:17 1.txt -rw-------. 1 lc1 lc1 0 12月 12 17:07 yum.log [lichao@test-01 tmp]$ ls -l /tmp/1 总用量 4 drwxr-xr-x. 2 root root 6 12月 23 03:25 2 -rw-rw-r--. 1 lichao root 0 12月 23 07:20 2.txt [lichao@test-01 tmp]$
防删除位,文件是否能被用户删除,主要看用户对文件所在的目录是否具备写权限,若是没有写权限,就不能删除该目录下的文件,也不能添加新的文件,若是想让用户有添加新文件可是不能删除别的用户的文件,则须要改属性,设置该属性后,就算用户对目录具备写权限,也不能删除其余用户的文件it
[root@test-01 tmp]# chmod 777 /tmp/1 给一个目录赋予777的权限 [root@test-01 tmp]# touch /tmp/1/123.t 在该目录下建立一个空文件 [root@test-01 tmp]# su lichao 切换到普通用户 [lichao@test-01 tmp]$ rm -f /tmp/1/123.t 使用普通用户删除该文件 [lichao@test-01 tmp]$ tree /tmp/1 成功删除 /tmp/1 ├── 1.txt ├── 1_txt.swn ├── 1_txt.swo ├── 1_txt.swp ├── 2 └── 2.txt
[root@test-01 ~]# chmod o+t /tmp/1 给这个目录添加sticky bit 属性 [root@test-01 ~]# touch /tmp/1/123.t 使用root再次建立123.t空文件 [root@test-01 ~]# tree /tmp/1 查看建立结果 /tmp/1 ├── 123.t ├── 1.txt ├── 1_txt.swn ├── 1_txt.swo ├── 1_txt.swp ├── 2 └── 2.txt 1 directory, 6 files
[lichao@test-01 tmp]$ rm -f /tmp/1/123.t 使用普通用户,再次删除该目录下的文件 rm: 没法删除"/tmp/1/123.t": 不容许的操做 没法删除 [lichao@test-01 tmp]$
软连接 至关于windows里面的快捷方式,它的命令是ln -s 源文件 快捷方式 与其余命令不一样的是执行这条命令,源文件放在前面test
[root@test-01 ~]# cp /etc/passwd /tmp/1 [root@test-01 ~]# tree /tmp /tmp ├── 1 │ ├── 123.t │ ├── 1.txt │ ├── 1_txt.swn │ ├── 1_txt.swo │ ├── 1_txt.swp │ ├── 2 │ ├── 2.txt │ └── passwd ├── 1.txt └── yum.log 2 directories, 9 files [root@test-01 ~]# ln -s /tmp/1/passwd /root/pawd [root@test-01 ~]# ls -l /root 总用量 4 drwxr-xr-x. 2 root root 6 12月 19 08:17 4 -rw-------. 1 root root 973 12月 12 17:09 anaconda-ks.cfg lrwxrwxrwx. 1 root root 13 12月 23 08:01 pawd -> /tmp/1/passwd [root@test-01 ~]#
ln -s 也能够对目录使用,就是说目录也能够作软连接,可是一旦源文件丢失,软连接就会提示错误。file
硬连接 硬连接不能做用在目录上,也不能跨分区作硬连接,作完硬连接能够删除源文件,硬连接不受影响。硬连接至关于源文件的一层皮权限