Set_uid set_gid stick_bit 软连接 硬连接

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

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

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

/usr/bin/passwdui

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

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


添加set_uid权限对象

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

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

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

受权后普通用户可使用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": 不容许将硬连接指向目录

相关文章
相关标签/搜索