用户的特殊权利

用户的特殊权利

一、特殊位

1、suid

suid针对文件/程序时,具备临时获得属主的权限。

suid (s—替换   uid--- 用户地址)----s  chmod  u+s  usr/bin/cat (赋予cat—s 权限)

2、sgid

针对目录授权,可以使目录下新建文件,继承目录的属组权限。

、创建目录

mkdir     /tmp/dir-sgid

、创建用户和组

groupadd  xiaozu

useradd   u1   -G  xiaozu

useradd   u2   -G xiaozu

、修改目录的权限

chown  .xiaozu   /tmp/dir-sgid

chmod     g=rwx  /tmp/dir-sgid

、切换用户测试

su -  u1

touch    /tmp/dir-sgid/u1-1.txt

su -  u2

touch    /tmp/dir-sgid/u2-1.txt

、增加sgid位

chmod g+s  /tmp/dir-sgid/

观察用户在新建文件时,文件会自动继承目录的属组

3、stick

针对目录设置,目录内的文件,仅属主能删除

chmod   o+t  /tmp/dir-sgid/

切换用户,只能删除自己的文件。

二、文件属性chattr

1、用途

常用于锁定某个文件,拒绝修改。



2、分类

 image.png

3、案例

先创建新文件进行对比。查看默认权限。

[root@localhost ~]# touch file100

[root@localhost ~]# lsattr file100

-------------- file100

加上不能删除的属性。

[root@localhost ~]# chattr +i file100

查看不同属性

[root@localhost ~]# lsattr file100

----i--------- file100

尝试删除

[root@localhost ~]# rm -rf file100

rm: cannot remove `file100': Operation not permitted

将属性还原

[root@localhost ~]# chattr -i file100

三、进程掩码 umask

示例1: 在shell进程中创建文件,先查看当前用户的umask权限

[root@localhost ~]# umask           

0022

[root@localhost ~]# touch file800

[root@localhost ~]# mkdir dir800

[root@localhost ~]# ll -d dir800 file800

drwxr-xr-x. 2 root root 4096 3月  11 19:40 dir800

-rw-r--r--. 1 root root    0 3月  11 19:40 file800

示例2:修改shell umask值(临时)

[root@localhost ~]# umask 000

[root@localhost ~]# mkdir dir900

[root@localhost ~]# touch file900

[root@localhost ~]# ll -d dir900 file900

drwxrwxrwx. 2 root root 4096 3月  11 19:44 dir900

-rw-rw-rw-. 1 root root    0 3月  11 19:44 file900

 

 


猜你喜欢

转载自blog.51cto.com/15135903/2666670