一、文件系统部分

- 普通文件(文本文件,二进制文件,压缩文件,电影,图片。。。)
d 目录文件(蓝色)
b 设备文件(块设备)存储设备硬盘,U盘 /dev/sda, /dev/sda1
c 设备文件(字符设备)打印机,终端 /dev/tty1
l 链接文件(淡蓝色)
s 套接字文件
p 管道文件

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

二、文件权限部分

1、基本权限UGO

[root@localhost ~]# chmod 7777 file7(默认文件权限为644,无执行权限) [root@localhost ~]# ll -d /root/file7 -rwsrwsrwt. 1 root root 0 7月  23 08:28 /root/file7 [root@localhost tmp]# chmod a=rwx file1 //所有人等于读写执行
[root@localhost tmp]# chmod a=- file1 //所有人没有权限
[root@localhost tmp]# chmod ug=rw,o=r file1 //属主属组等于读写,其他人只读
[root@localhost tmp]# ll file1 //以长模式方式查看文件权限
-rw-rw-r-- 1 alice it 17 10-25 16:45 file1 //显示的结果
 [root@localhost tmp]# chmod a=rwx file1 //所有人等于读写执行
[root@localhost tmp]# chmod a=- file1 //所有人没有权限
[root@localhost tmp]# chmod ug=rw,o=r file1 //属主属组等于读写,其他人只读
[root@localhost tmp]# ll file1 //以长模式方式查看文件权限
-rw-rw-r-- 1 alice it 17 10-25 16:45 file1 //显示的结果

-      //表普通文件

rwx  //读、写、执行(数字表示4、2、1)

a所有人,= 表覆盖

s是此处含有x权限,当去除x权限则为S。

s分为suid和sgid,suid可以为普通用户提权,sgid可以让组属性得以继承。

如下:

[root@localhost ~]#chmod -x file7 [root@localhost ~]# ll -d /root/file7 -rwSrwSrwT. 1 root root 0 7月  23 08:28 /root/file7 [root@tianyun ~]# chmod u+s /usr/bin/cat [alice@tianyun ~]$ cat /root/file1.txt(没有提权的普通用户是不允许进入/root)

t类似s,有x权限时为小写,当去除x权限则为T

t为特殊权限sticky,设置t后,即使是777权限的文件夹(root创),不同普通用户在里面创的文件,互相之间不允许删除他人所创文件。

2、基本权限 ACL

acl权限的理解:假如有一个test.txt文件,只有属主和属组有rwx权限,其他用户没权限。有一个用户既不在该用户属组也不是属主,想要访问test.txt文件,就得通过acl权限

。即acl权限可以针对单个用户。

设置:

[root@tianyun ~]# touch /home/test.txt [root@tianyun ~]# ll /home/test.txt -rw-r--r-- 1 root root 0 10-26 13:59 /home/test.txt [root@tianyun ~]# setfacl -m u:alice:rw /home/test.txt //增加用户alice权限
[root@tianyun ~]# setfacl -m u:jack:- /home/test.txt //增加用户jack权限
[root@tianyun ~]# setfacl -m o::rw /home/test.txt

查看:

[root@tianyun ~]# getfacl /home/test.txt//查看文件有哪些ACL权限。
 如何删除一条acl,如何删除所有acl呢? [root@tianyun ~]# ll /home/test.txt [root@tianyun ~]# getfacl /home/test.txt -rw-rw-r--+ 1 root root 0 10-26 13:59 /home/test.txt(+表示有acl权限) [root@tianyun ~]# setfacl -m g:hr:r /home/test.txt [root@tianyun ~]# setfacl -x g:hr /home/test.txt //删除组hr的acl权限
[root@tianyun ~]# setfacl -b /home/test.txt //删除所有acl权限
 [root@tianyun ~]# getfacl file1 |setfacl --set-file=- file2 //复制file1的ACL权限给file2

3、mask权限

acl权限中有个"mask"的选项,它就是ACL权限的最大权限,现在是rwx,当你设置某个用户或组的ACL权限时,要跟mask的权限“相与”之后产生的权限才是该用户的最终权限,也就是加入mask的最大权限是rx,但是你给st用户设置的是rwx权限,此时st用户它的权限只有rx的权限,因为与最大权限“相与”得出的结果就是rx。

4、特殊权限chattr:常用于锁定某个文件,拒绝修改。

设置:

[root@tianyun ~]# man chattr [root@tianyun ~]# chattr +a file100             //只能追加
[root@tianyun ~]# chattr +i file200             //不能更改,重命名,删除
[root@tianyun ~]# chattr +A file300            //不能更改访问时间。

查看:

[root@tianyun ~]# lsattr file100 file200 file300 -----a-------e- file100 ----i--------e- file200 -------A-----e- file300

还原:

[root@tianyun ~]# chattr -a file100 [root@tianyun ~]# chattr -i file200 [root@tianyun ~]# chattr -A file300

注意:chattr设置文件属性(权限),针对所有用户,包括root。

 三、sudo提权

1、root授予wang账号权限 [root@node1 ~]# chmod 700 /var/log/messages [root@node1 ~]# ll /var/log/messages -rwx------ 1 root root 2145 Oct  7 03:41 /var/log/messages [root@node1 ~]# vim /etc/sudoers root ALL=(ALL) ALL wang 192.168.40.132=(root)  /bin/cat  /var/log/messages*,! /bin/cat  /var/log/messages*  * (注意cat的路径,“,”和“!” !表示禁止) [root@node1 ~]# cd /etc/sudoers.d/ (检查子配置文件,可能冲突) [root@node1 sudoers.d]# ls [root@node1 sudoers.d]# [root@node1 ~]#su - wang [wang@node1 ~]$ sudo cat /var/log/messages [sudo] password for wang: ......

 

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄