特殊权限set_uid 该权限只能赋予二进制可执行文件,授权后普通用户在执行该文件时临时拥有它的所有者的权限

目录也可添加该权限,但无实际意义

[root@24centos7-01 /]# which passwd

/usr/bin/passwd

[root@24centos7-01 /]# ls -l /usr/bin/passwd

-rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd


添加set_uid权限

[root@24centos7-01 /]# chmod u+s /usr/bin/ls

[root@24centos7-01 /]# ls -l /usr/bin/ls

-rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls

授权后普通用户可以使用ls使用

[root@24centos7-01 ~]# su - vitus

[vitus@24centos7-01 ~]$ ls -l /root

总用量 4

-rw-------. 1 root root 1422 10月 13 05:50 anaconda-ks.cfg

drwxr-xr-x 3 root root 42 10月 20 21:19 showtime

drwxr-xr-x 2 root root 45 10月 20 21:37 test



特殊权限set_gid 该权限只能赋予二进制可执行文件,授权后普通用户在执行该文件时临时拥有它的所有者的所属组的权限

可以作用在文件和目录上,当对像是文件时,和set_uid效果相同,可使执行该文件的普通用户临时拥有所属主的权限;对象是目录时,当创建子文件或目录时,所创建的文件或目录的所属组和该目录保持一致


添加set_gid权限

[root@24centos7-01 /]# chmod g+s /usr/bin/ls

[root@24centos7-01 /]# ls -l /usr/bin/ls

-rwxr-sr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls

添加后普通用户可使用

[vitus@24centos7-01 ~]$ ls -ld /root/

dr-xr-x---. 5 root root 207 10月 20 22:24 /root/


[root@24centos7-01 tmp]# chown :vitus test

[root@24centos7-01 tmp]# ls -ld test

dr-xr-xr-x 2 root vitus 22 10月 22 21:48 test

[root@24centos7-01 tmp]# chmod g+s test

[root@24centos7-01 tmp]# ls -ld test

dr-xr-sr-x 2 root vitus 22 10月 22 21:50 test

[root@24centos7-01 tmp]# mkdir test/abc

[root@24centos7-01 tmp]# ls -l test

总用量 4

drwxr-sr-x 2 root vitus 6 10月 22 21:51 abc

-rw-r--r-- 1 root root 7 10月 22 21:05 test.txt

[root@24centos7-01 tmp]# touch test/tee.txt

[root@24centos7-01 tmp]# ls -l test

总用量 4

drwxr-sr-x 2 root vitus 6 10月 22 21:51 abc

-rw-r--r-- 1 root vitus 0 10月 22 21:53 tee.txt


[root@24centos7-01 tmp]# chmod g-s test

[root@24centos7-01 tmp]# ls -ld test

dr-xr--r-x 4 root vitus 76 10月 22 21:54 test

[root@24centos7-01 tmp]# ls -l test

总用量 4

drwxr-sr-x 2 root vitus 6 10月 22 21:51 abc

-rw-r--r-- 1 root vitus 0 10月 22 21:53 tee.txt

[root@24centos7-01 tmp]# mkdir test/abc1

[root@24centos7-01 tmp]# touch test/tee1.txt

[root@24centos7-01 tmp]# ls -l test

总用量 4

drwxr-sr-x 2 root vitus 6 10月 22 21:51 abc

drwxr-xr-x 2 root root 6 10月 22 21:57 abc1

-rw-r--r-- 1 root root 0 10月 22 21:57 tee1.txt

-rw-r--r-- 1 root vitus 0 10月 22 21:53 tee.txt


特殊权限stick_bit 防删除位

chmod o+t directoryname

[root@24centos7-01 tmp]# chmod o+t test

[root@24centos7-01 tmp]# chmod 777 test

[root@24centos7-01 test]# su - user1

上一次登录:日 10月 2223:13:17 CST 2689pxs/0 上

[user1@24centos7-01 ~]$ cd /tmp/test

[user1@24centos7-01 test]$ touch vitus.txt

[user1@24centos7-01 test]$ ll

总用量 0

-rw-rw-r-- 1 user1 user1 0 10月 22 23:16 vitus.txt

[user1@24centos7-01 test]$ 登出

[root@24centos7-01 test]# su - vitus

上一次登录:日 10月 2223:13:49 CST 2689pxs/0 上

[vitus@24centos7-01 ~]$ cd /tmp/test

[vitus@24centos7-01 test]$ ll

总用量 0

-rw-rw-r-- 1 user1 user1 0 10月 22 23:16 vitus.txt

[vitus@24centos7-01 test]$ rm -f vitus.txt

[vitus@24centos7-01 test]$ ll

[vitus@24centos7-01 test]$ ll

总用量 0

 

[user1@24centos7-01 ~]$ ls -ld /tmp/

drwxrwxrwt. 13 root root 4096 10月 22 23:04 /tmp/

[vitus@24centos7-01 tmp]$ touch vitus.txt

[vitus@24centos7-01 tmp]$ ls -l

总用量 12

drwxr-xr-x 2 root root 6 10月 22 18:46 1

-rw-r--r-- 1 root root 0 10月 22 18:45 1.txt

drwxrwxr-x 2 root root 6 10月 22 18:48 2

-rw-rw-r-- 1 root root 0 10月 22 18:46 2.txt

-rw-r--r-- 1 vitus vitus 0 10月 22 23:04 vitus.txt

[vitus@24centos7-01 tmp]$ 登出

[root@24centos7-01 tmp]# su - user1

上一次登录:日 10月 2222:59:58 CST 2689pxs/0 上

[user1@24centos7-01 ~]$ rm -f /tmp/vitus.txt

rm: 无法删除"/tmp/vitus.txt": 不允许的操作



软链接 做软链接时建议使用绝对路径

ln -s 源文件 目标文件

[root@24centos7-01 tmp]# mkdir test

[root@24centos7-01 tmp]# ls -ld test/

drwxr-xr-x 2 root root 6 10月 22 23:25 test/

[root@24centos7-01 tmp]# cd test

[root@24centos7-01 test]# touch vitus

[root@24centos7-01 test]# ll

总用量 0

-rw-r--r-- 1 root root 0 10月 22 23:25 vitus

[root@24centos7-01 test]# ln -s /tmp/test/vitus /tmp/vitus

[root@24centos7-01 test]# cd ..

[root@24centos7-01 tmp]# ll

总用量 0

drwxr-xr-x 2 root root 19 10月 22 23:25 test

lrwxrwxrwx 1 root root 15 10月 22 23:26 vitus -> /tmp/test/vitus

 

[root@24centos7-01 test]# rm -f vitus

[root@24centos7-01 test]# cd ..

[root@24centos7-01 tmp]# ls -l

总用量 0

drwxr-xr-x 2 root root 6 10月 22 23:29 test

lrwxrwxrwx 1 root root 15 10月 22 23:26 vitus -> /tmp/test/vitus

 

硬链接 不支持目录,仅支持文件

硬连接指通过索引节点来进行连接。在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(Inode Index)。在Linux中,多个文件名指向同一索引节点是存在的。一般这种连接就是硬连接。硬连接的作用是允许一个文件拥有多个有效路径名,这样用户就可以建立硬连接到重要文件,以防止误删的功能。其原因如上所述,因为对应该目录的索引节点有一个以上的连接。只删除一个连接并不影响索引节点本身和其它的连接,只有当最后一个连接被删除后,文件的数据块及目录的连接才会被释放。也就是说,文件真正删除的条件是与之相关的所有硬连接文件均被删除

[root@24centos7-01 /]# ln/boot/config-3.10.0-514.el7.x86_64 /tmp/config

ln: 无法创建硬链接"/tmp/config" =>"/boot/config-3.10.0-514.el7.x86_64": 无效的跨设备连接

[root@24centos7-01 /]# ln -s/boot/config-3.10.0-514.el7.x86_64 /tmp/config

 

[root@24centos7-01 tmp]# ll

总用量 0

lrwxrwxrwx 1 root root 34 10月 23 20:35 config ->/boot/config-3.10.0-514.el7.x86_64

drwxr-xr-x 2 root root 6 10月 22 23:29 test

[root@24centos7-01 tmp]# ln /tmp/test /tmp/test_link

ln: "/tmp/test": 不允许将硬链接指向目录