用户的特殊权利
用户的特殊权利
一、特殊位
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、分类
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
更多相关文章
- HULK容器镜像仓库简介
- Filebeat 收集日志的那些事儿
- RPM打包之路
- 文本文件内容查找 grep
- Oracle Linux 7.9+Oracle 12c+ASM安装文档--3、GRID软件安装
- find工具 查找文件或目录
- 微信PC版重磅更新!2个困扰多年的大麻烦,这次终于解决了
- 一个Python程序,可以帮助您自动备份文件
- Mac 电脑如何对文件进行批量重命名?