权限
umask
默认值为0022
| 0 | 0 | 2 | 2 |
|---|---|---|---|
| Special bit | u | g | o |
- 默认权限
- 目录的默认权限是 777 - umask = 755
- 文件的默认权限是目录的默认权限去掉执行权限(x = 1):755 - 111 = 644
- 非特权用户默认的 umask = 0022(0022,且在/etc/bashrc中定义
~ 目录权限将为 777 - 022 = 755(rwxr-xr-x)
~ 文件权限将为 777 - 022 - 111 = 644(rw-r–r–) - root的默认umask = 022(0022)
- SUID
Command run with permissions of the owner of the command, not executor of the command.
在u位:
| r | w | x | 描述 |
|---|---|---|---|
| s | x + SUID,文件原来有执行权限 | ||
| S | - + SUID,文件原来没有执行权限 |
- SGID
Command runs with group affiliation of the group of the command.Files created in directories with the SGID bit set have group affiliations of the group of the directory.
应用于一个目录,任何人在该目录里创建的文件及目录会自动属于该目录的组。
在g位:
| r | w | x | 描述 |
|---|---|---|---|
| s | x + SGID,文件组成员拥有执行权限 | ||
| S | - + SGID,文件组成员不拥有执行权限 |
- Sticky-bit
Files in directories with the sticky-bit set can only be removed by the owner and root, regardless of the write permissions of the directory.
在o位:
| r | w | x | 描述 |
|---|---|---|---|
| t | x + Sticky-bit,文件原来有执行权限 | ||
| T | - + Sticky-bit,文件原来没有执行权限 |
- 特殊权限的总结
| special permissions | executable | directory |
|---|---|---|
| SUID | Command run with permissions of the owner of the command, not executor of the command. Such as: ping. | N/A |
| SGID | Command runs with group affiliation of the group of the command. | File created in directories with the SGID bit set have group affiliations of the group of the directory. |
| Sticky-bit | N/A | Files in directories with the sticky bit set can only be removed or modified by the owner and root, regardless of the write permission. Such as: /tmp. Often both the Sticky bit and the SGID permission will be set on a project directory. |
- 相关命令
chmod u+s exefile chmod 4755 exefile ls -ld /apath chmod g+s /apath chmod 2771 /apath ls -ld /apath chmod o+t /apath chmod 1777 /apath ls -ld /apath- 其他
- SUID只能应用于可执行文件。
- SGID可应用于可执行文件,也可应用于目录。
- Sticky-bit只能应用于目录。
- SUID和SGID可同时出现,special bits = 6。当同时出现时,SUID的优先级高于SGID。
- SUID和Sticky-bit不可能同时出现,special bits ≠ 5。
- ls -l的回显数字
[user@bee-a admin]$ ll total 36 drwxrwxr-x. 2 user user 59 Jun 20 07:53 bak -rw-rw-r--. 1 user user 644 Jun 16 22:38 get_sys_info.py drwxrwxr-x. 5 user user 41 Jun 16 22:38 __pycache__ -rw-r--r--. 1 user user 3736 Jun 18 13:13 repond.xml -rw-rw-r--. 1 user user 407 Jun 19 22:38 test1.csv -rw-rw-r--. 1 user user 162 Jun 19 21:31 test1.txt -rw-rw-r--. 1 user user 407 Jun 19 22:42 test2.csv -rw-rw-r--. 1 user user 497 Jun 20 12:50 test3.txt -rw-rw-r--. 1 user user 429 Jun 20 12:43 test4.txt -rw-rw-r--. 1 user user 181 Jun 19 22:02 test.csv -rw-rw-r--. 1 user user 1161 Jun 18 13:52 test.xml 第二列的数字: 2 表示只有 . 和 .. 两个子目录 5 表示除. 和 .. 两个子目录外还有3个子目录 第一列表示文件类型: - regula file d directory l symbolic link b block special file : U盘,磁盘,光驱等存储设备 c character special file : 键盘等I/O设备 p named pipe s socket