特殊权限set_uid
1.s权限:set_uid 作用在用户上面 (1)当一个命令有s权限时,除了所有者所属组外的其他用户使用该命令时,会临时被赋予该命令所有者的身份; (2)赋予s权限的命令是二进制文件,可执行文件
[root@weix-01 ~]# ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd
2.给一个文件授权s权限:
[root@weix-01 ~]# chmod u+s /usr/bin/ls
[root@weix-01 ~]# ls -l /usr/bin/ls
-rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
[root@weix-01 ~]# su - weixing01
上一次登录:四 12月 21 14:55:37 CST 2017pts/0 上
[weixing01@weix-01 ~]$ ls /root
111 123 1.txt 1.txt~ 2.txt 3.txt anaconda-ks.cfg.1
3.S+x=s权限
[root@weix-01 ~]# chmod u=rws !$
chmod u=rws /usr/bin/ls
[root@weix-01 ~]# !ls
ls -l /usr/bin/ls
-rwSr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
[root@weix-01 ~]# chmod u+x /usr/bin/ls
[root@weix-01 ~]# !ls
ls -l /usr/bin/ls
-rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
特殊权限set_gid
1.s权限:set_gid作用在组上面,让普通用户临时拥有所属组的身份
[root@weix-01 ~]# chmod g+s /usr/bin/ls
[root@weix-01 ~]# ls -l /usr/bin/ls
-rwxr-sr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
2.当作用在文件时与set_gid用法一样,让普通用户临时拥有所属组的身份;当作用在目录上时,当你创建子目录或者子文件时,创建的子目录、子文件的所属组和该目录的所属组保持一致。
[root@weix-01 ~]# chmod g+s 123
[root@weix-01 ~]# ls -ld 123
drwxr-sr-x. 2 root root 6 12月 20 16:20 123
[root@weix-01 ~]# chown :weix01 123
chown: 无效的组: ":weix01"
[root@weix-01 ~]# chown :weixing01 123
[root@weix-01 ~]# touch 123/weixlinux
[root@weix-01 ~]# ls -l 123/
总用量 0
-rw-r--r--. 1 root weixing01 0 12月 21 15:31 weixlinux
[root@weix-01 ~]# mkdir 123/am
[root@weix-01 ~]# ls -l 123/
总用量 0
drwxr-sr-x. 2 root weixing01 6 12月 21 15:32 am
-rw-r--r--. 1 root weixing01 0 12月 21 15:31 weixlinux
[root@weix-01 ~]# chmod g-s 123
[root@weix-01 ~]# touch 123/weix0234
[root@weix-01 ~]# mkdir 123/am1
[root@weix-01 ~]# ls -l 123
总用量 0
drwxr-sr-x. 2 root weixing01 6 12月 21 15:32 am
drwxr-xr-x. 2 root root 6 12月 21 15:33 am1
-rw-r--r--. 1 root root 0 12月 21 15:33 weix0234
-rw-r--r--. 1 root weixing01 0 12月 21 15:31 weixlinux
特殊权限stick_bit
1.t权限:stick_bit防删除位
[root@weix-01 ~]# ls -ld /tmp
drwxrwxrwt. 11 root root 4096 12月 21 15:40 /tmp #t权限即是stick_bit权限
作用:防止别的用户删除自己的文件
2.删除一个目录和文件看的不是它本身的权限,要看他上级目录的权限,但是加上s权限后就无法删除了
软链接文件
1.类似Windows下面的超链接:路径越长,链接文件越大
[root@weix-01 ~]# ls -l /bin
lrwxrwxrwx. 1 root root 7 12月 11 23:52 /bin -> usr/bin
2.软链接可以节省空间,且能同步:ln -s 源文件 链接文件
[root@weix-01 ~]# ln -s /root/2.txt /tmp/weix01/
[root@weix-01 ~]# ls -l tmp/weix01/
ls: 无法访问tmp/weix01/: 没有那个文件或目录
[root@weix-01 ~]# ls -l /tmp/weix01/
总用量 4
-rwxrwx---. 1 root root 0 12月 20 15:39 1.txt
drwxrwx---. 3 root root 15 12月 18 17:04 2
lrwxrwxrwx. 1 root root 11 12月 21 16:31 2.txt -> /root/2.txt
-rwxrwx---. 1 root root 846 12月 19 15:08 passwd
3.可以链接文件也可以链接目录:
[root@weix-01 ~]# ln -s /tmp/weix01/ /root/111/weix02
[root@weix-01 ~]# ls -l /root/111
总用量 4
-rw-r--r--. 1 root root 65 12月 20 16:59 12.txt
drwxr-xr-x. 2 root root 6 12月 20 16:53 222
lrwxrwxrwx. 1 root root 12 12月 21 16:34 weix02 -> /tmp/weix01/
4.在同一目录下,可以使用相对路径,但是最好使用绝对路径 5.当一个磁盘快被占满,且有服务一直在产生文件时,可以采用以下办法:
[root@weix-01 ~]# cp /boot/weix.log /weix.log^C #复制该文件到一个空余较多的目录
[root@weix-01 ~]# rm /boot/weix.log ;ln -s /weix.log /boot/weix.log^C #删除原文件,并做个软链接到原路径
硬链接文件
1.硬链接不支持目录,只能对文件做硬链接
[root@weix-01 ~]# ln 2.txt 2_hard.txt
[root@weix-01 ~]# ln -s 2.txt 2_soft.txt
[root@weix-01 ~]# ls -l
总用量 16
drwxrwxr--. 3 root root 45 12月 21 16:34 111
drwxr-xr-x. 4 root weixing01 60 12月 21 15:33 123
-rw-r--r--. 1 root root 65 12月 20 16:49 1.txt
-rw-r--r--. 1 root root 0 12月 20 16:36 1.txt~
-rwx------. 2 root root 846 12月 19 15:18 2_hard.txt
lrwxrwxrwx. 1 root root 5 12月 21 16:51 2_soft.txt -> 2.txt
-rwx------. 2 root root 846 12月 19 15:18 2.txt
-rw-rw-r--. 1 root root 0 12月 20 16:27 3.txt
lrwxrwxrwx. 1 root root 12 12月 21 16:37 4.txt -> /tmp/yum.log
-rw-------. 1 root root 3956 12月 19 16:43 anaconda-ks.cfg.1
2.删除源文件对于硬链接没影响,文件还是正常,硬链接iNode号相同,不会占用多余空间 3.不能跨分区建立硬链接