set uid 、set gid 、sticky bit、软链接、硬链接
2017-12-23 00:00
204 查看
一、set uid
该权限针对二进制可执行文件,是普通用户在执行该文件时临时具有该文件所有者的权限[root@test-01 ~]# ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd [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 [root@test-01 ~]# chmod u+s /usr/bin/ls [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 ls: 无法打开目录.: 权限不够 [lichao@test-01 root]$ ls 4 anaconda-ks.cfg
上面两段代码需要穿插着看,一开始没有赋予/use/bin/ls set_uid权限时,普通用户是无法使用这个命令,然后通过执行chmod u+s /usr/bin/ls这条命令使普通用户在执行ls时暂时拥有了root的权限,所以能够执行。
二、set gid
set gid 属性可以作用在二进制可执行文件上,也可以作用在目录上。当作用在可执行文件上时跟set uid 作用累死,它会使普通用户在执行这个文件时具有文件所属组的权限。目录被设置这个属性后,任何用户在这个目录下创建的文件都具有和该目录所属组相同的组。[root@test-01 tmp]# chmod g+s /tmp/1 [lichao@test-01 tmp]$ touch /tmp/1.txt [lichao@test-01 tmp]$ touch /tmp/1/2.txt [lichao@test-01 tmp]$ ls -l /tmp 总用量 4 drwxr-srwx. 3 root root 4096 12月 23 07:20 1 -rw-rw-r--. 1 lichao lichao 0 12月 23 07:17 1.txt -rw-------. 1 lc1 lc1 0 12月 12 17:07 yum.log [lichao@test-01 tmp]$ ls -l /tmp/1 总用量 4 drwxr-xr-x. 2 root root 6 12月 23 03:25 2 -rw-rw-r--. 1 lichao root 0 12月 23 07:20 2.txt [lichao@test-01 tmp]$
三、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]$
四、软链接、硬链接
软链接相当于windows里面的快捷方式,它的命令是ln -s 源文件 快捷方式 与其他命令不同的是执行这条命令,源文件放在前面
[root@test-01 ~]# cp /etc/passwd /tmp/1 [root@test-01 ~]# tree /tmp /tmp ├── 1 │ ├── 123.t │ ├── 1.txt │ ├── 1_txt.swn │ ├── 1_txt.swo │ ├── 1_txt.swp │ ├── 2 │ ├── 2.txt │ └── passwd ├── 1.txt └── yum.log 2 directories, 9 files [root@test-01 ~]# ln -s /tmp/1/passwd /root/pawd [root@test-01 ~]# ls -l /root 总用量 4 drwxr-xr-x. 2 root root 6 12月 19 08:17 4 -rw-------. 1 root root 973 12月 12 17:09 anaconda-ks.cfg lrwxrwxrwx. 1 root root 13 12月 23 08:01 pawd -> /tmp/1/passwd [root@test-01 ~]#
ln -s 也可以对目录使用,就是说目录也可以做软链接,但是一旦源文件丢失,软链接就会提示错误。
硬链接
硬链接不能作用在目录上,也不能跨分区做硬链接,做完硬链接可以删除源文件,硬链接不受影响。硬链接相当于源文件的一层皮
相关文章推荐
- set uid 、set gid 、sticky bit、软链接、硬链接
- 特殊权限之set uid,set gid,sticky bit以及软链接和硬链接
- 几个特殊权限(set uid , set gid , sticky bit),软连接,硬链接
- 求set uid ,set gid,sticky bit的三个权限的详细说明
- linux中的set UID、set GID、sticky Bit
- set uid,set gid,sticky bit的三个权限的详细说明
- set uid, set gid,sticky bit详解
- 文件与目录权限中的set uid ;set gid;sticky bit
- 特殊权限set uid、set gid、stick bit和软链接与硬链接
- chmod 命令 set uid ,set gid,sticky bit 说明
- set uid,set gid,sticky bit详解
- set uid ,set gid,sticky bit的三个权限的详细说明
- set uid ,set gid,sticky bit的三个权限的详细说明
- 特殊权限 set uid 、set gid 、 sticky_bit
- 强制位(set uid和set gid)与冒险位(sticky)的特别权限
- Set uid, gid,sticky bit的三个权限的详细说明
- linux之档案基本权限、隐藏权限、特殊权限set uid、set gid、sticky
- Set uid, gid,sticky bit的三个权限的详细说明
- linux学习(九)set_uid、set_gid、stick_bit、软链接、硬链接
- 2周第4次课 特殊权限set_uid、set_gid、stick_bit 软链接 硬链接