1.set_uid:对二进制可执行文件有效。用户对于该文件具有x的权限。在执行该文件的过程中有效。用户将临时具有该文件所有者的权限.表现为在所有者权限端多了一个S。

[root@localhost ~]# ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd

2.添加set_uid权限, chmod u+s file ,user用户能够执行 ls 命令,注意 s 为小写是表示所有者有执行(x)权限,S时所有者没有执行(x)权限。

[user@localhost ~]$ ls /root/
ls: 无法打开目录/root/: 权限不够

[root@localhost ~]# chmod u+s /usr/bin/ls
[root@localhost ~]# ls -l /usr/bin/ls
-rwSr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls

[user@localhost ~]$ ls /root/
11.txt 2.txt data my.cnf newdir outputfile splash.xpm.gz

3.去掉权限,chmod u-s file 

[root@localhost ~]# chmod u-s /usr/bin/ls
[root@localhost ~]# ls -l /usr/bin/ls
-rw-r-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls

4.set_gid:对二进制文件和目录有效,作用在文件时和set_uid功能相似,文件在执行时拥有所属组的权限,作用在目录时,任何用户创建的子文件和子目录都有该目录所属组的文件。表现为s,在所属组多了一个s.

[root@localhost opt]# ls -ld dir
drwxr-xr-x. 2 root root 6 12月 22 08:00 dir
[root@localhost opt]# chmod g+s dir
[root@localhost opt]# ls -ld dir
drwxr-sr-x. 2 root root 6 12月 22 08:00 dir

[root@localhost opt]# mkdir dir/22
[root@localhost opt]# touch dir/1.txt
[root@localhost opt]# ls -l dir
总用量 0
-rw-r--r--. 1 root grouptest 0 12月 22 08:08 1.txt
drwxr-sr-x. 2 root grouptest 6 12月 22 08:08 22

[root@localhost opt]# chmod g-s dir
[root@localhost opt]# touch /dir/2.txt
touch: 无法创建"/dir/2.txt": 没有那个文件或目录
[root@localhost opt]# touch dir/2.txt
[root@localhost opt]# ls -l dir
总用量 0
-rw-r--r--. 1 root grouptest 0 12月 22 08:08 1.txt
drwxr-sr-x. 2 root grouptest 6 12月 22 08:08 22
-rw-r--r--. 1 root root 0 12月 22 08:12 2.txt

可以看到,在添加了该权限后,dir目录下创建的目录和文件都和该目录保持一致,再去掉该权限后,再次在该目录下创建的文件或目录就变了。

5.stick bit:防删除位,设置的目的是为了防止被别的用户误删资料。表现形式为在其他用户字段多了一个t.

[root@localhost tmp]# ls -ld
drwxrwxrwt. 180 root root 16384 12月 22 09:18 
[root@localhost tmp]# mkdir nn.txt

user@localhost tmp]$ rm -rf nn.txt/
rm: 无法删除"nn.txt/": 不允许的操作

[root@localhost tmp]# chmod o-t /tmp/
[root@localhost tmp]# ls -ld /tmp/
drwxrwxrwx. 181 root root 16384 12月 22 09:23 /tmp/

[user@localhost tmp]$ rm -rf nn.txt/
[user@localhost tmp]$

去掉该权限后,任何用户都可以删除了。

 

6.硬链接:硬链接就是同一个文件使用了多个别名,一个inode号对应多个文件名。可以有效防止误删。

[root@localhost opt]# touch 2.txt
[root@localhost opt]# echo 222 >2.txt
[root@localhost opt]# cat 2.txt
222
[root@localhost opt]# mkdir test
[root@localhost opt]# cd test/
[root@localhost test]# ln /opt/2.txt 1.txt
[root@localhost test]# cat 1.txt
222

[root@localhost test]# ls -i 1.txt
33730584 1.txt
[root@localhost test]# ls -i /opt/2.txt
33730584 /opt/2.txt

[root@localhost opt]# rm -rf 2.txt
[root@localhost opt]# cd test/
[root@localhost test]# cat 1.txt
222

[root@localhost opt]# ls
22 5.txt rh test
[root@localhost opt]# cd test/
[root@localhost test]# ln /opt/22/ 55
ln: "/opt/22/": 不允许将硬链接指向目录

由此我们可以看到1.txt 是 2.txt 的硬链接,两者都指向同一个INODE.同时删除源文件,还有别的文件指向inode。目录不能做硬链接。

7.软链接:类似于windos 下的快捷方式。创建软链接要加 -s ,且不能删除源文件。目录可以做软链接。

root@localhost opt]# touch 3.txt
[root@localhost opt]# cd test/
[root@localhost test]# ln -s /opt/3.txt 5.txt
[root@localhost test]# ls -l
总用量 4
-rw-r--r--. 1 root root 4 12月 22 08:52 1.txt
lrwxrwxrwx. 1 root root 10 12月 22 08:59 5.txt -> /opt/3.txt

[root@localhost opt]# rm -rf 3.txt
[root@localhost opt]# cd test
[root@localhost test]# ls
1.txt 5.txt
[root@localhost test]# cat 5.txt
cat: 5.txt: 没有那个文件或目录

删除原文件,软链接就不能用了

[root@localhost test]# ln -s /opt/22/ 55
[root@localhost test]# ls -l
总用量 4
-rw-r--r--. 1 root root 4 12月 22 08:52 1.txt
lrwxrwxrwx. 1 root root 8 12月 22 09:06 55 -> /opt/22/
lrwxrwxrwx. 1 root root 10 12月 22 08:59 5.txt -> /opt/3.txt

可以看到,22 这个目录在test下作了一个55 的软链接。

posted on 2017-12-22 08:13  天梭  阅读(95)  评论(0编辑  收藏  举报