- sticky 冒险位(黏贴位)
- 限定:只作用于目录
- 功能:任何人都可以在一个目录下建立文件,却只有root 和建立者本人才可以删除文件
- 特征:在other 位的x 显示为T 或t,t 代表包含了x 权限,T 代表未包含x 权限
- [root@localhost ~]# ls -lrt / |grep tmp drwxrwxrwt.
- 8 root root 94208 8月 30 17:53 tmp
- [root@localhost data]# chmod o+xt temp/
- [root@localhost data]# ll
- 总用量 4
- d--------t 4 root root 4096 8月 30 17:38 temp
- [root@localhost data]# chmod o-xt temp/
- [root@localhost data]# chmod o+t temp/
- [root@localhost data]# ll
- 总用量 4
- d--------T 4 root root 4096 8月 30 17:38 temp
- [root@localhost data]# clear
- [root@localhost data]#
- [root@localhost ~]# useradd A
- [root@localhost ~]# useradd B
- [A@localhost ~]$ cd /home/
- [A@localhost home]$ ls -lrt
- total 36
- drwx------ 4 A A 4096 Aug 30 17:01 A
- drwx------ 4 B B 4096 Aug 30 17:01 B
- [A@localhost home]$ chmod o+r A/
- [A@localhost home]$ ls -lrt
- total 36
- drwx---r-- 4 A A 4096 Aug 30 17:01 A
- drwx------ 4 B B 4096 Aug 30 17:01 B
- [A@localhost home]$ exit
- logout
- [root@localhost ~]# su - B
- [B@localhost ~]$ ls -lart /home/A/
- ls: cannot access /home/A/.mozilla: Permission denied
- ls: cannot access /home/A/..: Permission denied
- ls: cannot access /home/A/.gnome2: Permission denied
- ls: cannot access /home/A/.: Permission denied
- ls: cannot access /home/A/.bash_profile: Permission denied
- ls: cannot access /home/A/.bashrc: Permission denied
- ls: cannot access /home/A/.bash_logout: Permission denied
- ls: cannot access /home/A/.bash_history: Permission denied
- total 0
- d????????? ? ? ? ? ? .mozilla
- d????????? ? ? ? ? ? .gnome2
- -????????? ? ? ? ? ? .bashrc
- -????????? ? ? ? ? ? .bash_profile
- -????????? ? ? ? ? ? .bash_logout
- -????????? ? ? ? ? ? .bash_history
- d????????? ? ? ? ? ? ..
- d????????? ? ? ? ? ? .
- [B@localhost ~]$ cd /home/A/
- -bash: cd: /home/A/: Permission denied
- [B@localhost ~]$exit
- logout
- [root@localhost ~]# su - A
- [A@localhost ~]$ cd /home/
- [A@localhost home]$ ls -lrt
- total 36
- drwx---r-- 4 A A 4096 Aug 30 17:01 A
- drwx------ 4 B B 4096 Aug 30 17:01 B
- [A@localhost home]$ chmod o+x A/
- [A@localhost home]$ ls -lrt
- total 36
- drwx---r-x 4 A A 4096 Aug 30 17:01 A
- drwx------ 4 B B 4096 Aug 30 17:01 B
- [A@localhost home]$ exit
- logout
- [root@localhost ~]# su - B
- [B@localhost ~]$ cd /home/A/
- [B@localhost A]$ ls -lart
- total 32
- drwxr-xr-x 2 A A 4096 Nov 12 2010 .gnome2
- -rw-r--r-- 1 A A 124 May 30 2011 .bashrc
- -rw-r--r-- 1 A A 176 May 30 2011 .bash_profile
- -rw-r--r-- 1 A A 18 May 30 2011 .bash_logout
- drwxr-xr-x 4 A A 4096 Dec 15 2011 .mozilla
- drwxr-xr-x. 7 root root 4096 Aug 30 16:59 ..
- drwx---r-x 4 A A 4096 Aug 30 17:01 .
- -rw------- 1 A A 200 Aug 30 17:12 .bash_history
- [B@localhost A]$
- 总结:针对于目录,其他用户必须有X执行权限,才可以进入目录并浏览目录中的文件。
- 文件的权限
- [root@localhost home]# ll
- 总计 32
- drwx------ 4 blue bule 4096 04-07 23:11 blue
- drwx------ 17 Demigod Demigod 4096 04-07 21:08 Demigod
- drwx------ 2 root root 16384 04-03 02:25 lost+found
- drwx------ 4 red red 4096 04-07 22:23 red
- ---------- 代表文件的权限
- 第一个字符代表文件类型
- - 普通文件 d 目录文件 l 链接文件 b 块文件 c 字符文件 p 管道文件 s socket 网络借口文件
- 第二三四个字符表示当前用户user的权限 r w x 分别代表读 写 执行权限
- 第五六七个字符表示组权限group
- 第八九十个字符代表其他用户的权限others
- 我们以ll 来查看文件的具体信息 其中包括了权限信息
- 其他部分所表示的含义分别为:
- 4 当前有多少连接 blue 所有者(uid) bule 所有组(gid) 4096 文件大小 04-07 23:11 最后修改日期 blue文件名
- 其中blue blue 是与/etc/passwd文件与/etc/group文件中的uid与gid 匹配而找到的用户名称,若无法匹配到用户名则会显示uid与gid数值。
- 修改权限的命令
- chmod 修改权限 其参数有
- chmod u(g,o) +/- r(w,x) 文件名 也可 a+参数 a 表示全部
- [root@localhost home]# touch apple.txt
- -rw-r--r-- 1 root root 0 04-08 01:53 apple.txt
- [root@localhost home]# chmod o+x apple.txt
- -rw-r--r-x 1 root root 0 04-08 01:53 apple.txt
- 给文件加了一个执行权限,其他权限也可以类似的 给予或者取消
- chmod -R 可以改变目录以及目录下所有文件的权限
- drwx------ 4 blue bule 4096 04-07 23:11 blue
- -rw-r--r-- 1 root root 0 04-08 01:59 orange
- [root@localhost home]# chmod -R 666 blue
- drw-rw-rw- 4 blue bule 4096 04-08 01:59 blue
- -rw-rw-rw- 1 root root 0 04-08 01:59 orange
- 其中666也表示权限
- 权限的数字表示形式 r w x 以二进制来定义 1为有这个权限 0为没有这个权限
- 则 全有 则是 111 全无是000 换算为10进制排列组合 有 7 6 5 4 3 2 1 0
- 7 r w x 6 r w - 5 r - x 4 r - - 3 - w x 2 - w - 1 - - x 0 - - -
- 修改所有者的命令
- chown 用户名uid.(:)组名gid 文件名
- chown -R 可以修改目录以及目录下所有文件的所有者
- drwx-wx--x 4 blue bule 4096 04-08 01:59 blue
- [root@localhost home]# chown -R red.red blue
- drwx-wx--x 4 red red 4096 04-08 01:59 blue
- 特殊权限SUID SGID Stick
- SUID SGID为文件可能拥有的特殊权限 当一个文件拥有该权限,就会以文件所有者(组)的身份去执行文件
- -rwsr-xr-x 1 root root 0 04-08 01:53 apple.txt
- 我们看这个文件 ,uid的执行权限变为了s 那么 该文件就会以拥有者root的权限运行
- 普通用户修改密码的指令/usr/bin/passwd
- [root@localhost home]# ll /usr/bin/passwd
- -rwsr-xr-x 1 root root 22960 2006-07-17 /usr/bin/passwd
- 用户修改密码会调用/etc/shadow配置文件 而该文件是个只读文件
- -r-------- 1 root root 1340 04-07 22:49 /etc/shadow
- 普通用户权限是无法修改的,但我们看/usr/bin/passwd这个程序有s的特殊权限,它将以root的身份去运行,而root权限可以修改/etc/shadow配置文件。
- /bin/ping 是另外个有特殊权限的命令
- -rwsr-xr-x 1 root root 35864 01-21 12:40 /bin/ping
- ICMP在封装时,只能由root封装,因此该程序也有s权限。
- 若给予一般的文件s特殊权限 是不安全的
- Stick 与 SGID是目录可能有的特殊权限
- 一个文件被赋予Stick(t)权限后 该文件只能被拥有者删除。