linux文件系统上的特殊权限及细致权限ACL
linux文件系统上的特殊权限及细致权限ACL
Chattr命令:常用重要参数与选项:
lsattr 命令:显示特定属性语法格式:lsattr [-adR] 文件或目录 [[email?protected] data]#touch testdir [[email?protected] data]#chattr +i testdir [[email?protected] data]#ls scripts testdir [[email?protected] data]#ll total 4 drwxr-xr-x. 5 root root 4096 Mar 19 19:38 scripts -rw-r--r--. 1 root root 0 Mar 19 19:39 testdir [[email?protected] data]#rm -r testdir rm: remove regular empty file ‘testdir’? y rm: cannot remove ‘testdir’: Operation not permitted [[email?protected] data]#lsattr testdir ----i----------- testdir 文件特殊权限:SUID,SGID,SBIT我们一直使用的文件重要权限,那就是rwx这三个读、写、执行权限,那么除了这个就没有其他权限了吗? [[email?protected] data]#ll -d /tmp /usr/bin/passwd drwxrwxrwt. 32 root root 4096 Mar 19 19:57 /tmp -rwsr-xr-x. 1 root root 27832 Jun 10 2014 /usr/bin/passwd [[email?protected] data]#lsattr -a /etc/shadow ---------------- /etc/shadow 特殊权限SUID:我们都知道/etc/shadow文件的权限为000;那么就是除了root外的所有用户将对这个文件没有任何权限,然而当普通用户使用passwd命令时,发现我们能修改用户密码并保存进/etc/shadow中,那岂不是就前后矛盾了?原因就是/usr/bin/passwd上的特殊权限s,当普通用户执行passwd命令时,会临时拥有root的权限。 [[email?protected] data]#ll /bin/cat -rwxr-xr-x. 1 root root 54160 Oct 31 03:16 /bin/cat [[email?protected] data]#su gong [[email?protected] data]$ cat /etc/shadow cat: /etc/shadow: Permission denied 特殊权限SGID:当s标志在文件的拥有者的x项目为SUID,那s在群组的x时则称为Set GID,简写为SGID;SUID可作用在文件或目录上; [[email?protected] data]$ ls -l testfile //查看文件的权限,在群组位置有的执行位上为s,other用户对程序只有x执行权限; -rw-r-s--x 1 root gong 10 Mar 20 09:31 testfile [[email?protected] data]$ id hh //用户hh属于组gong的成员 uid=1004(hh) gid=1004(hh) groups=1004(hh),1000(gong) [[email?protected] data]$ cat testfile //这时用户hh在执行的过程中获得了该程序群组的支持,从而可以读取文件内容; d sd sd 当SGID作用在文件上,其起到的功能为: [[email?protected] data]#ll -d testdir/ //查看目录发现群组对该目录有s权限,其他用户只有w权限 drwxrws-w- 2 root gong 6 Mar 20 10:01 testdir/ [[email?protected] data]#su hh //切换用户 [[email?protected] testdir]$ id //用户hh时群组gong的组员 uid=1004(hh) gid=1004(hh) groups=1004(hh),1000(gong) [[email?protected] data]$ cd testdir/ //hh用户有进入目录权限 [[email?protected] testdir]$ touch testfile1 //hh用户有创建新文件的权限 [[email?protected] testdir]$ ll //发现hh用户创建的文件的群组自动属于gong total 0 -rw-rw-r-- 1 hh gong 0 Mar 20 10:06 testfile1 [[email?protected] testdir]$ echo 22222 > testfile1 //hh用户可修改文件 [[email?protected] testdir]$ cat testfile1 //hh用户可读取文件 22222 [[email?protected] testdir]$ rm testfile1 //hh用户可删除文件 特殊权限SBIT:SBIT只对目录有效,功能是: [[email?protected] data]#ls -ld testdir/ //目录testdir的other的权限位上为t,权限为777 drwxrwsrwt 2 root root 23 Mar 20 10:20 testdir/ [[email?protected] testdir]#su hh [[email?protected] testdir]$ ll -d testfile1 -rwxrwxrwx 1 gong gong 0 Mar 20 10:20 testfile1 //文件的所有者和所属组为gong,hh用户对该文件拥有rwx权限 [[email?protected] testdir]$ rm -f testfile1 //但hh用户不能删除此文件,只能root和文件属主才能删除 rm: cannot remove ‘testfile1’: Operation not permitted 主机的细致权限规划:ACL的使用ACL 是 Access Control List 的缩写,主要的目的是在提供传统的 owner,group,others 的 read,write,execute 权限之外的细部权限设定。ACL 可以针对单一使用者,单一文件或目录来进行 r,w,x 的权限规范,对于需要特殊权限的使用状况非常有帮助。 [[email?protected] data]#dmesg |grep -i acl [ 0.869680] systemd[1]: systemd 219 running in system mode. (+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN) [ 3.264996] SGI XFS with ACLs,security attributes,no debug enabled 使用ACL: [[email?protected] data]#touch acl_testfile //创建测试文件 [[email?protected] data]#ll acl_testfile //查看文件权限 -rw-r--r-- 1 root root 0 Mar 20 10:44 acl_testfile [[email?protected] data]#setfacl -m u:gong:rw acl_testfile //使用setfacl给用户gong设置权限 [[email?protected] data]#ll acl_testfile //发现文件的权限后面多了一个+号 -rw-rw-r--+ 1 root root 0 Mar 20 10:44 acl_testfile [[email?protected] data]#setfacl -m u::rwx acl_testfile //当使用setfacl设置文件权限中间用户空时,发现默认将文件所有者的修改 [[email?protected] data]#ll acl_testfile -rwxrw-r--+ 1 root root 0 Mar 20 10:44 acl_testfile 查看文件的具体acl权限:getfacl filename [[email?protected] data]#getfacl acl_testfile # file: acl_testfile # owner: root # group: root user::rwx user:gong:rw- group::r-- mask::rw- other::r-- setfacl :设定某个目录/文件的ACL规范,对群组的细致acl权限设置:setfacl -m g:group:rwx filename [[email?protected] data]#setfacl -m g:gong:r acl_testfile [[email?protected] data]#getfacl acl_testfile # file: acl_testfile # owner: root # group: root user::rwx user:gong:rw- group::r-- group:gong:r-- mask::rw- other::r-- (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |