9月17日任务node
2.18 特殊权限set_uidcentos
2.19 特殊权限set_gidbash
2.20 特殊权限stick_bitssh
2.21 软连接文件ui
2.22 硬链接文件centos7
设置了set_uid的二进制文件,其余用户执行时,将临时拥有该文件全部者的权限,以此执行!最经常使用的命令passwd的二进制文件就被赋予了set_uid特殊权限!spa
设置set_uid的前提:必须是 二进制可执行文件,目录无效3d
在u的权限组内没有x权限时,设置set_uid后s位将变为大写(S)。code
#未设置set_uid,普通用户查看/root目录 [castiel@centos7 ~]$ /usr/bin/ls /root /usr/bin/ls: 没法打开目录/root: 权限不够 #设置set_uid后,能够以root权限查看/root [root@centos7 ~]# chmod u+s /usr/bin/ls [root@centos7 ~]# ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117656 ... /usr/bin/ls [root@centos7 ~]# su - castiel [castiel@centos7 ~]$ /usr/bin/ls /root 111 anaconda-ks.cfg
[root@centos7 ~]# ls -l /usr/bin/ls -rwSr-xr-x. 1 root root 117656 ... /usr/bin/ls
设置了set_gid的文件执行时将拥有文件所属组(group)的权限。进程
此外对目录设置set_gid后,执行时当前命令的用户的所属组将会成为在该目录下新建立的文件、目录的所属组(group),
没有设置的其内文件的所属组是当前用户的所属组。
[root@centos7 tmp]# mkdir test [root@centos7 tmp]# ls -ld test/ drwxr-xr-x. 2 root root 6 ... test/ [root@centos7 tmp]# chown :castiel test/ [root@centos7 tmp]# ls -ld test/ drwxr-xr-x. 2 root castiel 6 ... test/ # 未设置前建立目录和文件,与后续进行对比 [root@centos7 tmp]# mkdir test/111 [root@centos7 tmp]# touch test/222.txt #设置set_gid,随后建立新目录和文件 [root@centos7 tmp]# chmod g+s test/ [root@centos7 tmp]# mkdir test/333/ [root@centos7 tmp]# touch test/444.txt [root@centos7 tmp]# ls -l test/ 总用量 0 drwxr-xr-x. 2 root root 6 ... 111 -rw-r--r--. 1 root root 0 ... 222.txt drwxr-sr-x. 2 root castiel 6 ... 333 -rw-r--r--. 1 root castiel 0 ... 444.txt # 一样的去除掉group内的x权限,set_gid位显示为S. [root@localhost system]# chmod g-x /test [root@localhost system]# chmod g+s /test [root@localhost system]# ls -ld /test drwxr-Sr-x. 2 root root 6 ... /test
防删除位,对一个目录设置sticky_bit后,一个用户将没法删除目录内其余用户建立的文件!(root用户除外)
正常状况下,只要用户对该父目录拥有x权限,就能够删除目录下的文件、子目录,不须要关心用户对文件、子目录是否拥有x权限!
添加了sticky_bit权限后,能够防止其余用户误删。
[root@centos7 test]# ls -ld /test/ drwxr-xr-x. 2 root root 16 ... /test/ # 添加sticky_bit位 [root@centos7 test]# chmod o+t /test/ [root@centos7 test]# ls -ld /test/ drwxr-xr-t. 2 root root 16 ... /test/ # 一样的当没有x权限,sticky_bit显示为T [root@localhost system]# chmod o-x /test [root@localhost system]# chmod o+t /test [root@localhost system]# ls -ld /test drwxr-xr-T. 2 root root 6 ... /test
软连接文件至关于Windows下的快捷方式,文件类型为l。 系统目录/bin/目录就是/usr/bin/目录的软链接
使用方法:ln -s 目标文件/目录 软连接
好处:占用内存小
缺点:源文件/目录被删除或移动,软连接将失效
修改软连接文件的内容的实质为修改源文件,软连接是对其的引用!建立软连接最好使用绝对路径,不易出错!
对于一个空间很少的分区,若是有一个文件被进程所使用致使所占空间不断变大,这时若是不想该分区被数据写满,
能够先将该文件拷贝到其余大空间分区,并在原分区内建立软连接!!而后删除原处文件,原进程不受影响!
[root@centos7 test]# ls -l /bin lrwxrwxrwx. 1 root root 7 ... /bin -> usr/bin
使用方法: ln 源文件 硬链接文件
硬连接是对同一个文件所在内存地址的引用(inode号相等),硬连接和原文件互为硬连接!
删除其中一个文件,另外的文件不受影响!
修改其中一个文件,另外的文件内容也变化!
硬连接没法跨分区建立(多个分区有相同inode号,任意弄混)
!!不能对目录设置硬连接:
新建立的硬连接不会占用额外的空间!!由于其空间在建立源文件的时候就已经占用了,
对应于系统内的特定内存地址,硬连接只是是对该内存地址的引用。
[root@centos7 ~]# ls -ld . dr-xr-x---. 3 root root 173 ... . [root@centos7 ~]# ls -ild . /root/ /root/.ssh/.. 16797761 dr-xr-x---. 3 root root 173 ... . 16797761 dr-xr-x---. 3 root root 173 ... /root/ 16797761 dr-xr-x---. 3 root root 173 ... /root/.ssh/.. 对于一个目录而言,其内包含的3个子目录均可以表示该目录, 对目录设置硬连接会产生循环建立,陷入死循环!
[root@centos7 test]# ls -li 总用量 8 8812615 -rw-r--r--. 2 root root 8 ... 1.txt 8812615 -rw-r--r--. 2 root root 8 ... 2.txt [root@centos7 test]# du -sh /test/ 4.0K /test/ [root@centos7 test]# du -sh 1.txt 4.0K 1.txt [root@centos7 test]# du -sh 2.txt 4.0K 2.txt