`二周第四次课
2.18 特殊权限set_uid
2.19 特殊权限set_gid
2.20 特殊权限stick_bit
2.21 软链接文件
2.22 硬连接文件
特殊权限set_uid
set_uid 主要作用就是 普通用户临时拥有root的权限 必须是二进制文件 必须有 x 权限
案例:就是 password 这个命令
[root@CentOS-A test]# ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd //rws r-x r-x s就是set_uid
添加set_uid
命令
chomd u+s /usr/bin/ls //给ls 添加sut_uid
如果这个文件没有x 权限S 变成大写不影响使用
特殊权限set_gid
set_gid
文件时候和set_uid相识 用户拥有root组的权限
目录的时候 创建文件的时候 属组 跟父目录
特殊权限stick_bit
防删除位
[root@CentOS-A test]# ls -dl /tmp/
drwxrwxrwt. 9 root root 233 10月 24 03:36 /tmp/
[root@CentOS-A test]#
实验:
[root@CentOS-A test]# useradd test //增加用户 test
[root@CentOS-A test]# su – test //切换用户test
[test@CentOS-A ~]$ vi /tmp/test.txt //编辑tmp 下test.txt 写啥都行
[test@CentOS-A ~]$ su //切换到root
[root@CentOS-A tmp]# chmod 777 test.txt //给777 权限
[root@CentOS-A test]# useradd test2 //创建用户test2
[root@CentOS-A tmp]# su test2 //切换到test2 用户
[test2@CentOS-A tmp]$ cd /tmp/ //切换到tmp 目录下
[test2@CentOS-A tmp]$ rm test.txt //删除 结果不能删除
rm:是否删除有写保护的普通文件 “test.txt”?y
rm: 无法删除”test.txt”: 不允许的操作
[test2@CentOS-A tmp]$ ls -l test.txt //777 的权限不能删除 很奇怪吧。。这个就是防删除位
-rwxrwxrwx 1 test test 48 10月 24 09:36 test.txt
##软连接
相当于window 下的快捷方式
告警!!!!!!!!!!!!!!!!!
软连接必须用绝对路径
[test2@CentOS-A tmp]$ ls -l /lib64
lrwxrwxrwx. 1 root root 9 10月 23 14:43 /lib64 -> usr/lib64 //这个就是软连接
[root@CentOS-A tmp]# ln -s /tmp/yum.log /root/123 //文件软连接
[root@CentOS-A tmp]# ln -s /tmp/ /root/ // 目录软连接 tmp 为源文件 放到root下快捷方式
绿色为正常的
红色那个不正常 软连接失效

硬链接
硬链接不支持目录
不支持跨分区因为硬链接 是靠分区inode 来分配的不同分区 对应的inode 不一样
一个分区都有相对inode 。硬链接相当于cp 了一份 。删除一个另外一个不影响
分区容量不变化。
使用方法和 ln 源 目标
实验:
[root@CentOS-A tmp]# ln /tmp/yum.log /tmp/2.log //创建 tmp 下 yum.log 到2.log
[root@CentOS-A tmp]# ls -i /tmp/yum.log 2.log //查看 yum.log 和2.log 的inode 是否相通 结果一样
16777289 2.log 16777289 /tmp/yum.log
[root@CentOS-A tmp]# ln /tmp/yum.log /boot/yum.log
ln: 无法创建硬链接"/boot/yum.log" => "/tmp/yum.log": 无效的跨设备连接`
转载于:https://my.oschina.net/u/3709657/blog/1556993