linux系统特殊权限

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

setuid

实验

//我们先置空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
//解除限制
3. 进程掩码umask

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

4.特殊权限练习题

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值