本文共 2605 字,大约阅读时间需要 8 分钟。
文件默认权限 umask
若使用者创建为『文件』则默认『没有可运行( x )权限』,亦即只有 rw 这两个项目,也就是最大为 666 分,默认权限如下:-rw-rw-rw-创建文件时:(-rw-rw-rw-) - (-----w--w-) ==> -rw-r--r--若使用者创建为『目录』,则由於 x 与是否可以进入此目录有关,因此默认为所有权限均开放,亦即为 777 分,默认权限:drwxrwxrwx创建目录时:(drwxrwxrwx) - (d----w--w-) ==> drwxr-xr-x[root@www ~]# umask0022
[root@www ~]# touch test1
[root@www ~]# mkdir test2
[root@www ~]# ll
-rw-r--r-- 1 root root 0 Sep 27 00:25 test1
drwxr-xr-x 2 root root 4096 Sep 27 00:25 test2
设置umask:[root@www ~]# umask 002[root@www ~]# touch test3
[root@www ~]# mkdir test4
[root@www ~]# ll
-rw-rw-r-- 1 root root 0 Sep 27 00:36 test3
drwxrwxr-x 2 root root 4096 Sep 27 00:36 test4
例题: 假设你的 umask 为 003 ,请问该 umask 情况下,创建的文件与目录权限为? 答: umask 为 003 ,所以拿掉的权限为 --------wx,因此:文件: (-rw-rw-rw-) - (--------wx) = -rw-rw-r--
目录: (drwxrwxrwx) - (--------wx) = drwxrwxr--文件隐藏属性 :chattr lsattr
[root@www ~]# chattr [+-=][ASacdistu] 文件或目录名称选项与参数:
:添加某一个特殊参数,其他原本存在参数则不动。
= :配置一定,且仅有后面接的参数
a :当配置 a 之后,这个文件将只能添加数据,而不能删除也不能修改数据,只有root 才能配置这个属性。
i :这个 i 可就很厉害了!他可以让一个文件『不能被删除、改名、配置连结也无法写入或新增数据!』对於系统安全性有相当大的助益!只有 root 能配置此属性[root@www tmp]# chattr +i attrtest <==给予 i 的属性[root@www tmp]# rm attrtest <==尝试删除看看
rm: remove write-protected regular empty file `attrtest'? y
rm: cannot remove `attrtest': Operation not permitted <==操作不许可
你突然要新增使用者,却一直无法新增!别怀疑,赶快去将 i 的属性拿掉[root@www ~]# lsattr [-adR] 文件或目录选项与参数:
-a :将隐藏档的属性也秀出来;
-d :如果接的是目录,仅列出目录本身的属性而非目录内的档名;
-R :连同子目录的数据也一并列出来!
[root@www tmp]# chattr +aij attrtest[root@www tmp]# lsattr attrtest
----ia---j--- attrtest
文件特殊权限: SUID, SGID, SBIT
4 为 SUID 2 为 SGID 1 为 SBITs 与 t 都是取代 x 这个权限的
SUID 不是用在目录上,而 SBIT 不是用在文件上Set UID
SUID 权限仅对二进位程序(binary program)有效; 运行者对於该程序需要具有 x 的可运行权限; 本权限仅在运行该程序的过程中有效 (run-time); 运行者将具有该程序拥有者 (owner) 的权限。SGID 对二进位程序有用;
程序运行者对於该程序来说,需具备 x 的权限; 运行者在运行的过程中将会获得该程序群组的支持!Sticky Bit
当使用者对於此目录具有 w, x 权限,亦即具有写入的权限时; 当使用者在该目录下创建文件或目录时,仅有自己与 root 才有权力删除该文件[root@www ~]# cd /tmp
[root@www tmp]# touch test <==创建一个测试用空档
[root@www tmp]# chmod 4755 test; ls -l test <==加入具有 SUID 的权限
-rwsr-xr-x 1 root root 0 Sep 29 03:06 test
[root@www tmp]# chmod 6755 test; ls -l test <==加入具有 SUID/SGID 的权限
-rwsr-sr-x 1 root root 0 Sep 29 03:06 test
[root@www tmp]# chmod 1755 test; ls -l test <==加入 SBIT 的功能!
-rwxr-xr-t 1 root root 0 Sep 29 03:06 test
[root@www tmp]# chmod 7666 test; ls -l test <==具有空的 SUID/SGID 权限
-rwSrwSrwT 1 root root 0 Sep 29 03:06 test
[root@www tmp]# chmod u=rwxs,go=x test; ls -l test
-rws--x--x 1 root root 0 Aug 18 23:47 test
[root@www tmp]# chmod g+s,o+t test; ls -l test
-rws--s--t 1 root root 0 Aug 18 23:47 test
转载于:https://blog.51cto.com/mrkey/2064445