Linux 文件系统权限记序

字体大小: 中小 标准 ->行高大小: 标准

Linux 文件系统权限记序

用到程序:

chmod setfacl getfacl stat chattr lsattr
 chmod:设置文件权限
setfacl:设置访问控制列表(access control list)
 getfacl:查看访问控制列表
stat:显示inode内容(a|m|c)time内容
chattr:设置第二扩展文件的列表文件属性系统
lsattr:查看第二扩展文件的列表文件属性系统
setuid:使文件拥有和文件属主相同的x权限
setgid:使文件夹拥有和文件属组相同的x权限
sticky:使文件不可册除

Test:

  1. [root@nagios test]# touch setuid setgid sticky [root@nagios test]# chown -R nagios.nagios ./
  2. [root@nagios test]# chmod u+s setuid && chmod g+s setgid && chmod o+t sticky [root@nagios test]# ll
  3. total 0 -rw-r-Sr-- 1 nagios nagios 0 Mar 2800:41 setgid
  4. -rwSr--r-- 1 nagios nagios 0 Mar 2800:41 setuid -rw-r--r-T 1 nagios nagios 0 Mar 2800:41 sticky
  5. [root@nagios test]# su hello [hello@nagios test]$ pwd
  6. /root/test [hello@nagios test]$ echo hello >> setuid
  7. bash: setuid: Permission denied [hello@nagios test]$ sh setuid
  8. hello [nagios@nagios test]$ exit
  9. exit [root@nagios test]# chmod o+w sticky
  10. [root@nagios test]# su hello [hello@nagios test]$ ll sticky
  11. -rw-rw-rwT 1 nagios nagios 0 Mar 2800:45 sticky [hello@nagios test]$ rm sticky
  12. rm: cannot remove `sticky': Permission denied [hello@nagios test]$ stat sticky
  13. File: `sticky' Size: 0 Blocks: 0 IO Block: 4096 regular empty file
  14. Device: fd00h/64768d Inode: 134198 Links: 1 Access: (1666/-rw-rw-rwT) Uid: ( 500/ nagios) Gid: ( 500/ nagios)
  15. Access: 2013-03-2800:45:37.875928997 +0800 Modify: 2013-03-2800:45:37.875928997 +0800
  16. Change: 2013-03-2800:46:28.050580800 +0800

#setfacl and getfacl

user:: user: 属主权限 "::"均为属主 ":" 为特殊用户
group:: group: 组和特殊组
other:: 其它人
mask:: 除了属主和其他人之外的所有人
常用选项:
-d : 子目录继承父目录的特殊权限。
-R : 递归权限

查看是否支持ACL

  1. [root@nagios heelo]# tune2fs -l /dev/sda1 | grep option Default mount options: user_xattr acl

test:

  1. [root@nagios test]# touch setfacl [root@nagios test]# setfacl -m user::r,user:hello:rw setfacl
  2. [root@nagios test]# chown nagios.nagios setfacl [root@nagios test]# ll setfacl
  3. -r--rw-r--+ 1 nagios nagios 0 Mar 2800:52 setfacl [root@nagios test]# su nagios
  4. [nagios@nagios test]$ echo hello >> setfacl bash: setfacl: Permission denied
  5. [nagios@nagios test]$ exit exit
  6. [root@nagios test]# su hello [hello@nagios test]$ echo hello >> setfacl
  7. [hello@nagios test]$ cat setfacl hello
  8. [hello@nagios test]$ getfacl setfacl # file: setfacl
  9. # owner: nagios # group: nagios
  10. user::r-- user:hello:rw-
  11. group::r-- mask::rw-
  12. other::r--

#chattr and lsattr
Chattr +-=[acdeijstuADST].
A:Atime,告诉系统不要修改对这个文件的最后访问时间。
S:Sync,一旦应用程序对这个文件执行了写操作,使系统立刻把修改的结果写到磁盘。
a:Append Only,系统只允许在这个文件之后追加数据,不允许任何进程覆盖或截断这个文件。如果目录具有这个属性,系统将只允许在这个目录下建立和修改文件,而不允许删除任何文件。
i:Immutable,系统不允许对这个文件进行任何的修改。如果目录具有这个属性,那么任何的进程只能修改目录之下的文件,不允许建立和删除文件。
D:检查压缩文件中的错误。
d:No dump,在进行文件系统备份时,dump程序将忽略这个文件。
C:Compress,系统以透明的方式压缩这个文件。从这个文件读取时,返回的是解压之后的数据;而向这个文件中写入数据时,数据首先被压缩之后才写入磁盘。
s:Secure Delete,让系统在删除这个文件时,使用0填充文件所在的区域。
u:Undelete,当一个应用程序请求删除这个文件,系统会保留其数据块以便以后能够恢复删除这个文件。

test:

  1. [root@nagios test]# mkdir chattr [root@nagios test]# chattr +i chattr/
  2. [root@nagios test]# touch chattr/hello touch: cannot touch `chattr/hello': Permission denied
  3. [root@nagios test]# chattr -i +a chattr/ [root@nagios test]# touch chattr/hello && echo hello >>chattr/hello && cat chattr/hello
  4. hello [root@nagios test]# rm chattr/hello
  5. rm: remove regular file `chattr/hello'? y rm: cannot remove `chattr/hello': Operation not permitted

《完》

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/63983.html