linux系统特殊权限
1. linux系统特殊权限
- 1.1set_uid
- 1.2set_gid
- 1.3 sticky粘滞代
2. 权限属性chattr
3. 进程掩码umask
4. 特殊权限实验
1.linux系统特殊权限
对可执行文件的setuid或是setgid权限表示将以文件的用户或是组身份
运行命令,而不是以运行命令的用户身份,以password命令为例:
[root@hjh ~]# ll /usr/bin/passwd
-rwsr-xr-x. 1 root root 27832 Jun 10 2014 /usr/bin/passwd
目录粘滞位t
可以为文件删除设置特殊限制,仅文件所有者和root用户
可以删除目录中的文件
drwxrwxrwt. 13 root root 4096 Oct 4 20:22 /tmp/
对目录的setgid权限表示在该目录中创建的文件将继承该目录的组所属关系,而不是继承自创建用户 ,这通常用于组协作目录,将文件从默认的
专有组自动更改为共享组。
1.1set_uid
实验
//我们先置空other权限
[root@hjh ~]# chmod 640 /etc/passwd
[root@hjh ~]# ll /etc/passwd
-rw-r----- 1 root root 1521 Sep 25 18:55 /etc/passwd
//other用户hjh试着读取文件
[hjh@hjh ~]$ cat /etc/passwd
cat: /etc/passwd: Permission denied
//我们加上特殊权限suid
[root@hjh ~]# chmod 4755 /bin/cat
[root@hjh ~]# ll /bin/cat
-rwsr-xr-x. 1 root root 54080 Apr 11 2018 /bin/cat
//我们在用hjh去读取
[hjh@hjh ~]$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
1.2.set_gid
1.文件的有效执行组身份为文件的拥有组,而不是执行者的组身份
2.目录里新建的文件的拥有组会自动继承目录拥有者的身份
[root@hjh tmp]# mkdir test
[root@hjh tmp]# ll -d test
drwxr-xr-x 2 root root 6 Oct 4 21:43 test
[root@hjh tmp]# chmod 777 test
[root@hjh tmp]# ll -d test
drwxrwxrwx 2 root root 6 Oct 4 21:43 test
[hjh@hjh tmp]$ touch test/hjh.txt
[hjh@hjh tmp]$ ll test/hjh.txt
-rw-rw-r-- 1 5012 hjh 0 Oct 4 21:45 test/hjh.txt
[root@hjh tmp]# chmod 2777 test
[root@hjh tmp]# ll -d test
drwxrwsrwx 2 root root 21 Oct 4 21:45 test
[hjh@hjh tmp]$ touch test/hjh1.txt
[hjh@hjh tmp]$ ll test/hjh1.txt
-rw-rw-r-- 1 5012 root 0 Oct 4 21:47 test/hjh1.txt
1.3 sticky粘滞代
2. 权限属性chattr
设置文件属性(权限),针对所有用户,包括root。
选项 a :让文件或者目录仅可追加内容。
选项 i:不得任意更改文件或者目录
[root@hjh test]# touch file_a file_i
[root@hjh test]# lsattr *
---------------- file_a
---------------- file_i
[root@hjh test]# chattr +a file_a
[root@hjh test]# chattr +i file_i
[root@hjh test]# lsattr *
-----a---------- file_a
----i----------- file_i
[root@hjh test]# echo aaa > file_a
-bash: file_a: Operation not permitted
[root@hjh test]# rm -f file_a
rm: cannot remove ‘file_a’: Operation not permitted
[root@hjh test]# echo aaa >> file_a
[root@hjh test]# cat file_a
aaa
//可以看出 a权限不能删除不能覆盖 只能追加,适用于日志文件。
[root@hjh test]# echo iii > file_i
-bash: file_i: Permission denied
[root@hjh test]# echo iii >> file_i
-bash: file_i: Permission denied
[root@hjh test]# rm -f file_i
rm: cannot remove ‘file_i’: Operation not permitted
// i 权限无法写入无法删除
[root@hjh test]# chattr -a file_a
[root@hjh test]# chattr -i file_i
[root@hjh test]# lsattr *
---------------- file_a
---------------- file_i
//解除限制