set uid 、set gid 、sticky bit、软连接、硬连接

1、set uid

该特殊权限只能针对二进制可执行文件,执行该权限后会使普通用户在执行该文件时临时具备该文件全部者的权限windows

[root@test-01 ~]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[root@test-01 ~]# ls -l /usr/bin/ls
-rwxr-xr-x. 1 root root 117616 6月  10 2014 /usr/bin/ls   1、未赋予该命令set_uid 权限
[root@test-01 ~]# chmod u+s /usr/bin/ls   3、赋予该命令set_uid权限 
[root@test-01 ~]# !ls
ls -l /usr/bin/ls
-rwsr-xr-x. 1 root root 117616 6月  10 2014 /usr/bin/ls
[root@test-01 ~]# su lichao
[lichao@test-01 root]$ whoami
lichao
[lichao@test-01 root]$ ls     2、普通用户没法执行该命令
ls: 没法打开目录.: 权限不够
[lichao@test-01 root]$ ls	 4、普通用户能够执行该权限
4  anaconda-ks.cfg

上面两段代码须要穿插着看,没有赋予/use/bin/ls set_uid权限时,普通用户是没法使用这个命令,而后经过执行chmod u+s /usr/bin/ls这条命令使普通用户在执行ls时暂时拥有了root的权限,因此可以执行。ui

2、set gid

set gid 属性能够做用在二进制可执行文件上,也能够做用在目录上。看成用在可执行文件上时跟set uid 做用相似,它会使普通用户在执行这个文件时具备文件所属组的权限。目录被设置这个属性后,任何用户在这个目录下建立的文件都具备和该目录所属组相同的组。code

[root@localhost ~]# mkdir /media/123
[root@localhost ~]# chown :usr1 /media/123
[root@localhost ~]# mkdir /media/123/11
[root@localhost ~]# ls -lR /media/
/media/:
总用量 0
drwxr-xr-x. 3 root usr1 15 6月   9 07:12 123

/media/123:
总用量 0
drwxr-xr-x. 2 root root 6 6月   9 07:12 11  

/media/123/11:这里能够看到,虽然media/123属组是usr1,可是root在该目录下建立的目录11属组还是root
总用量 0
[root@localhost ~]# chmod g+s /media/123  给/media/123设置set_gid权限
[root@localhost ~]# mkdir /media/123/22
[root@localhost ~]# !ls
ls -lR /media/
/media/:
总用量 0
drwxr-sr-x. 4 root usr1 24 6月   9 07:13 123

/media/123:
总用量 0
drwxr-xr-x. 2 root root 6 6月   9 07:12 11
drwxr-sr-x. 2 root usr1 6 6月   9 07:13 22能够看到root新建立的目录22的属组继承了/media/123目录的属组

/media/123/11:
总用量 0

/media/123/22:
总用量 0

3、sticky bit

防删除位,文件是否能被用户删除,主要看用户对文件所在的目录是否具备写权限,若是没有写权限,就不能删除该目录下的文件,也不能添加新的文件,若是想让用户有添加新文件可是不能删除别的用户的文件,则须要该属性,设置该属性后,就算用户对目录具备写权限,也不能删除其余用户的文件继承

[root@test-01 tmp]# chmod 777 /tmp/1     给一个目录赋予777的权限
[root@test-01 tmp]# touch /tmp/1/123.t     在该目录下建立一个空文件
[root@test-01 tmp]# su lichao                   切换到普通用户
[lichao@test-01 tmp]$ rm -f /tmp/1/123.t   使用普通用户删除该文件
[lichao@test-01 tmp]$ tree /tmp/1              成功删除
/tmp/1
├── 1.txt
├── 1_txt.swn
├── 1_txt.swo
├── 1_txt.swp
├── 2
└── 2.txt
[root@test-01 ~]# chmod o+t /tmp/1            给这个目录添加sticky bit 属性
[root@test-01 ~]# touch /tmp/1/123.t           使用root再次建立123.t空文件
[root@test-01 ~]# tree /tmp/1                       查看建立结果
/tmp/1
├── 123.t
├── 1.txt
├── 1_txt.swn
├── 1_txt.swo
├── 1_txt.swp
├── 2
└── 2.txt

1 directory, 6 files
[lichao@test-01 tmp]$ rm -f /tmp/1/123.t      使用普通用户,再次删除该目录下的文件
rm: 没法删除"/tmp/1/123.t": 不容许的操做    没法删除
[lichao@test-01 tmp]$

4、软连接、硬连接

软连接 至关于windows里面的快捷方式,它的命令是ln -s 源文件 快捷方式 与其余命令不一样的是执行这条命令,源文件放在前面it

[root@localhost ~]# ln -s /etc/passwd /media/123/2.t
[root@localhost ~]# ls -lR /media
/media:
总用量 0
drwxr-sr-x. 4 root usr1 44 6月   9 07:31 123

/media/123:
总用量 0
drwxr-xr-x. 2 root root  6 6月   9 07:12 11
-rw-r--r--. 1 root usr1  0 6月   9 07:30 1.t
drwxr-sr-x. 2 root usr1  6 6月   9 07:13 22
lrwxrwxrwx. 1 root usr1 11 6月   9 07:31 2.t -> /etc/passwd

ln -s 也能够对目录使用,就是说目录也能够作软连接,可是一旦源文件丢失,软连接就会提示错误。test

硬连接 目录不能作硬连接,也不能跨分区作硬连接,作完硬连接能够删除源文件,硬连接不受影响,硬连接不一样于彻底复制了源文件,它不会占用额外空间。硬连接跟源文件指向同一个iNode号,硬连接和源文件至关于iNode的两层彻底同样的皮,真正的内容是有iNode控制的,随便删除一个都不会产生影响,可是不能将硬连接和源文件都删除。作硬连接的命令为:ln -*源文件 连接文件 *file

[root@localhost ~]# ln /etc/passwd /media/123/4.t
[root@localhost ~]# !ls
ls -li /media/123
总用量 4
 67887170 drwxr-xr-x. 2 root root   6 6月   9 07:12 11
   620177 -rw-r--r--. 1 root usr1   0 6月   9 07:30 1.t
101100372 drwxr-sr-x. 2 root usr1   6 6月   9 07:13 22
   620179 lrwxrwxrwx. 1 root usr1  11 6月   9 07:31 2.t -> /etc/passwd
 34232696 -rw-r--r--. 2 root root 959 6月   9 07:12 4.t
[root@localhost ~]# ls -li /etc/passwd
34232696 -rw-r--r--. 2 root root 959 6月   9 07:12 /etc/passwd
相关文章
相关标签/搜索