http://linux-wiki.cn/index.php?title=%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90&feed=atom&action=history
文件权限 - 修订历史
2024-03-29T13:25:18Z
本站上此页的修订历史
MediaWiki 1.17.0
http://linux-wiki.cn/index.php?title=%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90&diff=1774&oldid=prev
Chenxing在2012年2月5日 (日) 18:44
2012-02-05T18:44:38Z
<p></p>
<table style="background-color: white; color:black;">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">←上一修订</td>
<td colspan='2' style="background-color: white; color:black;">在2012年2月5日 (日) 18:44所做的修订版本</td>
</tr><tr><td colspan="2" class="diff-lineno">第1行:</td>
<td colspan="2" class="diff-lineno">第1行:</td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> 出于安全的考虑,<del class="diffchange diffchange-inline">[[ </del>多用户操作系统<del class="diffchange diffchange-inline">]] </del>需要具备保障个人隐私和系统安全的机制。在[[Linux]]中,无论是文档还是硬件设备都以文件的形式存在,相应地,安全机制也主要表现为对文件访问权限的控制。<ref>http://linux.chinaitlab.com/administer/38992.html</ref><ref>http://<del class="diffchange diffchange-inline">doc</del>.<del class="diffchange diffchange-inline">linuxpk</del>.<del class="diffchange diffchange-inline">com</del>/<del class="diffchange diffchange-inline">40848</del>.<del class="diffchange diffchange-inline">html</del></ref><ref>http://<del class="diffchange diffchange-inline">blog</del>.<del class="diffchange diffchange-inline">chinaunix</del>.<del class="diffchange diffchange-inline">net</del>/<del class="diffchange diffchange-inline">u2</del>/<del class="diffchange diffchange-inline">71216</del>/<del class="diffchange diffchange-inline">showart_734757</del>.html</ref></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> 出于安全的考虑,多用户操作系统需要具备保障个人隐私和系统安全的机制。在[[Linux]]中,无论是文档还是硬件设备都以文件的形式存在,相应地,安全机制也主要表现为对文件访问权限的控制。<ref><ins class="diffchange diffchange-inline">[</ins>http://linux.chinaitlab.com/administer/38992.html <ins class="diffchange diffchange-inline">Linux文件和目录访问权限设置]</ins></ref><ref><ins class="diffchange diffchange-inline">[</ins>http://<ins class="diffchange diffchange-inline">blog</ins>.<ins class="diffchange diffchange-inline">chinaunix</ins>.<ins class="diffchange diffchange-inline">net</ins>/<ins class="diffchange diffchange-inline">space</ins>.<ins class="diffchange diffchange-inline">php?uid=9408581&do=blog&id=2003865 Linux文件权限隐藏的细节深入分析]</ins></ref><ref><ins class="diffchange diffchange-inline">[</ins>http://<ins class="diffchange diffchange-inline">www</ins>.<ins class="diffchange diffchange-inline">ibm</ins>.<ins class="diffchange diffchange-inline">com</ins>/<ins class="diffchange diffchange-inline">developerworks</ins>/<ins class="diffchange diffchange-inline">cn</ins>/<ins class="diffchange diffchange-inline">linux/l-lpic1-v3-104-5/index</ins>.html<ins class="diffchange diffchange-inline">?ca=drs- IBM Developer Networks: 学习 Linux,101: 管理文件权限和所有权]</ins></ref></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{{Hint|除了本文所讨论的内容之外,[[SELinux]](Security-Enhanced Linux)是另一种著名的安全机制,它是美国国家安全局(NAS)对于强制访问控制的实现,是一种更为可靠,也明显更为复杂的安全机制。在[[Fedora]]和[[Red Hat Enterprise Linux]]上默认安装了这一机制。}}</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{{Hint|除了本文所讨论的内容之外,[[SELinux]](Security-Enhanced Linux)是另一种著名的安全机制,它是美国国家安全局(NAS)对于强制访问控制的实现,是一种更为可靠,也明显更为复杂的安全机制。在[[Fedora]]和[[Red Hat Enterprise Linux]]上默认安装了这一机制。}}</div></td></tr>
<tr><td colspan="2" class="diff-lineno">第6行:</td>
<td colspan="2" class="diff-lineno">第6行:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>===基础权限===</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>===基础权限===</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 要确定一个用户对某个文件或目录是否具有相应的权限,先要明确该用户与文件或目录之间的关系。在Linux系统中,定义了如下三种关系:</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 要确定一个用户对某个文件或目录是否具有相应的权限,先要明确该用户与文件或目录之间的关系。在Linux系统中,定义了如下三种关系:</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>;文件所有者(owner):拥有文件的用户 <del class="diffchange diffchange-inline">,通常 </del>是创建文件的用户。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>;文件所有者(owner):拥有文件的用户 <ins class="diffchange diffchange-inline">。创建文件时 </ins>是创建文件的用户 <ins class="diffchange diffchange-inline">(可用<tt>whoami</tt>命令查看) </ins>。</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>;组(group):文件所属的<del class="diffchange diffchange-inline">[[ </del>组<del class="diffchange diffchange-inline">]],通常是 </del>创建文件 <del class="diffchange diffchange-inline">的 </del>用户 <del class="diffchange diffchange-inline">所属 </del>的组。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>;组(group):文件所属的组 <ins class="diffchange diffchange-inline">。 </ins>创建文件 <ins class="diffchange diffchange-inline">时 </ins>用户的组 <ins class="diffchange diffchange-inline">(可用<tt>id</tt>命令查看) </ins>。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>;其他人(other):既不是文件所有者,也不是文件所属的组的成员的其他用户。</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>;其他人(other):既不是文件所有者,也不是文件所属的组的成员的其他用户。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td colspan="2" class="diff-lineno">第14行:</td>
<td colspan="2" class="diff-lineno">第14行:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{| class=wikitable</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{| class=wikitable</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>!权限 !! 简 !! 值 !! 对普通文件的作用 !! 对文件夹的作用</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>!权限 !! 简 !! 值 !! 对普通文件的作用 !! 对文件夹的作用<ins class="diffchange diffchange-inline"><ref>[http://www.slyar.com/blog/linux-folder-permission.html Linux文件夹权限 学习笔记]</ref></ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>| 读取 || r || 4 || 查看文件内容 || 列出目录中的文件(ls)</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>| 读取 || r || 4 || 查看文件内容 || 列出目录中的文件(ls)</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>| 写入 || w || 2 || 修改文件内容 || 在目录中删除 <del class="diffchange diffchange-inline">或 </del>添加文件</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>| 写入 || w || 2 || 修改文件内容 || 在目录中删除 <ins class="diffchange diffchange-inline">、 </ins>添加 <ins class="diffchange diffchange-inline">或重命名 </ins>文件<ins class="diffchange diffchange-inline">(夹)</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>| 执行 || x || 1 || 文件可以作为程序执行 || 访问子目录及文件及shell中cd到此目录 <del class="diffchange diffchange-inline">、</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>| 执行 || x || 1 || 文件可以作为程序执行 || 访问子目录及文件及shell中cd到此目录</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|}</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></center></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></center></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 上面的三种关系与三种操作权限的组合,构成了一个含有9个二进制位的权限标识。</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 上面的三种关系与三种操作权限的组合,构成了一个含有9个二进制位的权限标识。</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>===特殊权限===</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>===特殊权限===</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 还有三种与用户身份无关的三个文件权限属性。即'''SUID'''、'''SGID'''和'''Sticky'''。</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 还有三种与用户身份无关的三个文件权限属性。即'''SUID'''、'''SGID'''和'''Sticky'''。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>;SUID(Set User ID, 4):该属性只对有执行权限的文件有效,对目录无效。执行具有SUID权限的程序时,引发的进程的所有者是程序文件的所有者,而不是启动程序的用户(除非二者是同一个人)。比如,如果一个程序的所有者是root且具有SUID属性,一个普通用户执行此程序时,如同root执行此程序一样。<ref>http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/SetUserID.html</ref>'''请注意该属性对Shell脚本程序无效。'''该属性为一些特殊程序(如lpr)的启动带来了方便。但有时也带来了安全隐患:比如一个具有SUID属性的程序如果在执行时运行了一个shell,那么用户可以籍此得到系统的最高权限。SUID可用'''s'''表示。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>;SUID(Set User ID, 4):该属性只对有执行权限的文件有效,对目录无效。执行具有SUID权限的程序时,引发的进程的所有者是程序文件的所有者,而不是启动程序的用户(除非二者是同一个人)。比如,如果一个程序的所有者是root且具有SUID属性,一个普通用户执行此程序时,如同root执行此程序一样。<ref><ins class="diffchange diffchange-inline">[</ins>http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/SetUserID.html <ins class="diffchange diffchange-inline">Set-User-ID Permission for Executable Files]</ins></ref> <ins class="diffchange diffchange-inline">(</ins>'''请注意该属性对Shell脚本程序无效。''' <ins class="diffchange diffchange-inline">) </ins>该属性为一些特殊程序(如lpr)的启动带来了方便。但有时也带来了安全隐患:比如一个具有SUID属性的程序如果在执行时运行了一个shell,那么用户可以籍此得到系统的最高权限。SUID可用'''s'''表示。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{{Hint|consolehelper是一个更高级的用于提供用户权限的解决方案,见[[使用consolehelper获得root权限]]。}}</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{{Hint|consolehelper是一个更高级的用于提供用户权限的解决方案,见[[使用consolehelper获得root权限]]。}}</div></td></tr>
<tr><td colspan="2" class="diff-lineno">第50行:</td>
<td colspan="2" class="diff-lineno">第51行:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>  d<font color=blue>rwxrwxrwt</font> 12    root    root  16384 08-12 21:07 '''tmp'''</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>  d<font color=blue>rwxrwxrwt</font> 12    root    root  16384 08-12 21:07 '''tmp'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> 蓝色的部分就是权限字符串,权限表示三个为一组,依次是所有者权限、组权限、其他人权限。每组的顺序均 <del class="diffchange diffchange-inline">为rwx </del>,如果有相应权限,则表示成相应字母,如果不具有相应权限,则用-表示。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> 蓝色的部分就是权限字符串,权限表示三个为一组,依次是所有者权限、组权限、其他人权限。每组的顺序均 <ins class="diffchange diffchange-inline">为<tt>rwx</tt> </ins>,如果有相应权限,则表示成相应字母,如果不具有相应权限,则用<ins class="diffchange diffchange-inline"><tt></ins>-<ins class="diffchange diffchange-inline"></tt> </ins>表示。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 上面的例子中,第一行是一个普通文本文件,第二行是个普通的可执行程序,第三行是个普通的文件夹。第四行是带SUID、SGID的程序,最后一行则是''/tmp''的权限。</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 上面的例子中,第一行是一个普通文本文件,第二行是个普通的可执行程序,第三行是个普通的文件夹。第四行是带SUID、SGID的程序,最后一行则是''/tmp''的权限。</div></td></tr>
<tr><td colspan="2" class="diff-lineno">第59行:</td>
<td colspan="2" class="diff-lineno">第60行:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 而</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 而</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>  rw---x-w-=0(4+2)(1)(2)='''0612'''</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>  rw---x-w-=0(4+2)(1)(2)='''0612'''</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">{{Note|组权限覆盖其它人权限,如上例中,一个权限为<tt>0604</tt>的文件无法被其所属组的用户读取。}}</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>==修改权限==</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>==修改权限==</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> 文件所有者或超级用户可以修改一个文件的权限。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> 文件所有者或超级用户可以修改一个文件 <ins class="diffchange diffchange-inline">或目录 </ins>的权限 <ins class="diffchange diffchange-inline">。修改权限可以使用chmod命令,也可以使用桌面环境的文件管理程序。</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">如,<tt>chmod 700 foo</tt> 命令会将 ''foo'' 的权限更改为 700(见[[#数值表示]])。</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">除了使用八进制数值权限,还可以用 <tt>[ugoa][[+-=][rwxst]</tt> 格式设置相应权限。<ref>[http://www.ibm.com/developerworks/cn/linux/l-lpic3-315-1/index.html?ca=drs- IBM Developer Networks: 学习 Linux,302(混合环境): Linux 文件系统和共享/服务权限]</ref>第一个字符是u、g、 o 或 a 中的一个(分别表示用户、组、其他人和所有人)。还可以选择添加(+)、删除(-)或设置(=)各种不同权限。如</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline"> chmod u+x foo</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">可设置 foo 的执行位,并保持其他位不变。</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline"> chmod g-rw something</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">则可以移除组的读和写权限。</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">另一种使用 chmod 的方法是使用 <tt>--reference</tt> 参数:</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline"> chmod --reference file1 file2</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">可以让 file2 的权限与 file1 一样。</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">要更改文件的所有者,可使用 <tt>chown</tt> 命令。如</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline"> chown sean foo</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">命令可将 ''foo'' 的所有者更改为 sean。只有根用户可以修改文件的所有者 </ins>。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> 可以 <del class="diffchange diffchange-inline">使用[[chmod]]修 </del>改文件 <del class="diffchange diffchange-inline">或目录 </del>的 <del class="diffchange diffchange-inline">权限,也可以使 </del>用 <del class="diffchange diffchange-inline">桌面环境 </del>的 <del class="diffchange diffchange-inline">文件管理程序修改权限 </del>。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline"><tt>chgrp</tt> </ins> <ins class="diffchange diffchange-inline">命令 </ins>可以 <ins class="diffchange diffchange-inline">更 </ins>改文件的 <ins class="diffchange diffchange-inline">组。普通 </ins>用 <ins class="diffchange diffchange-inline">户必须属于新 </ins>的 <ins class="diffchange diffchange-inline">组 </ins>。  </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>==参考资料==</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>==参考资料==</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><references /></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><references /></div></td></tr>
</table>
Chenxing
http://linux-wiki.cn/index.php?title=%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90&diff=1662&oldid=prev
Chenxing: /* 基础权限 */
2011-11-12T03:23:16Z
<p><span class="autocomment">基础权限</span></p>
<table style="background-color: white; color:black;">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">←上一修订</td>
<td colspan='2' style="background-color: white; color:black;">在2011年11月12日 (六) 03:23所做的修订版本</td>
</tr><tr><td colspan="2" class="diff-lineno">第20行:</td>
<td colspan="2" class="diff-lineno">第20行:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>| 写入 || w || 2 || 修改文件内容 || 在目录中删除或添加文件</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>| 写入 || w || 2 || 修改文件内容 || 在目录中删除或添加文件</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>| 执行 || x || 1 || 文件可以作为程序执行 ||  <del class="diffchange diffchange-inline">进入 </del>到此目录<del class="diffchange diffchange-inline">(cd)</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>| 执行 || x || 1 || 文件可以作为程序执行 ||  <ins class="diffchange diffchange-inline">访问子目录及文件及shell中cd </ins>到此目录 <ins class="diffchange diffchange-inline">、</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|}</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></center></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></center></div></td></tr>
</table>
Chenxing
http://linux-wiki.cn/index.php?title=%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90&diff=1131&oldid=prev
Chenxing在2009年1月23日 (五) 10:29
2009-01-23T10:29:41Z
<p></p>
<table style="background-color: white; color:black;">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">←上一修订</td>
<td colspan='2' style="background-color: white; color:black;">在2009年1月23日 (五) 10:29所做的修订版本</td>
</tr><tr><td colspan="2" class="diff-lineno">第1行:</td>
<td colspan="2" class="diff-lineno">第1行:</td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> 出于安全的考虑,[[多用户操作系统]]需要具备保障个人隐私和系统安全的机制。在[[Linux]]中, <del class="diffchange diffchange-inline">这一 </del>机制主要表现为对文件访问权限的控制。<ref>http://linux.chinaitlab.com/administer/38992.html</ref><ref>http://doc.linuxpk.com/40848.html</ref><ref>http://blog.chinaunix.net/u2/71216/showart_734757.html</ref></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> 出于安全的考虑,[[多用户操作系统]]需要具备保障个人隐私和系统安全的机制。在[[Linux]]中, <ins class="diffchange diffchange-inline">无论是文档还是硬件设备都以文件的形式存在,相应地,安全 </ins>机制 <ins class="diffchange diffchange-inline">也 </ins>主要表现为对文件访问权限的控制。<ref>http://linux.chinaitlab.com/administer/38992.html</ref><ref>http://doc.linuxpk.com/40848.html</ref><ref>http://blog.chinaunix.net/u2/71216/showart_734757.html</ref></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{{Hint|除了本文所讨论的内容之外,[[SELinux]](Security-Enhanced Linux)是另一种著名的安全机制,它是美国国家安全局(NAS)对于强制访问控制的实现,是一种更为可靠,也明显更为复杂的安全机制。在[[Fedora]]和[[Red Hat Enterprise Linux]]上默认安装了这一机制。}}</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{{Hint|除了本文所讨论的内容之外,[[SELinux]](Security-Enhanced Linux)是另一种著名的安全机制,它是美国国家安全局(NAS)对于强制访问控制的实现,是一种更为可靠,也明显更为复杂的安全机制。在[[Fedora]]和[[Red Hat Enterprise Linux]]上默认安装了这一机制。}}</div></td></tr>
<tr><td colspan="2" class="diff-lineno">第10行:</td>
<td colspan="2" class="diff-lineno">第10行:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>;其他人(other):既不是文件所有者,也不是文件所属的组的成员的其他用户。</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>;其他人(other):既不是文件所有者,也不是文件所属的组的成员的其他用户。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> 根据用户对文件或目录操作种类的不同,又定义了三种操作权限:</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> 根据用户对文件或目录操作种类的不同,又定义了三种操作权限 <ins class="diffchange diffchange-inline">,并为每种权限赋予一个简写形式和数值(数值的用途[[#权限的表示|后面]]讨论) </ins>:</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><center></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><center></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{| class=wikitable</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{| class=wikitable</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>!权限 !! 简 <del class="diffchange diffchange-inline">写 </del>!! 对普通文件的作用 !! 对文件夹的作用</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>!权限 !! 简 <ins class="diffchange diffchange-inline">!! 值 </ins>!! 对普通文件的作用 !! 对文件夹的作用</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>| 读取 || r || 查看文件内容 || 列出目录中的文件(ls)</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>| 读取 || r <ins class="diffchange diffchange-inline">|| 4 </ins>|| 查看文件内容 || 列出目录中的文件(ls)</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>| 写入 || w || 修改文件内容 || 在目录中删除或添加文件</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>| 写入 || w <ins class="diffchange diffchange-inline">|| 2 </ins>|| 修改文件内容 || 在目录中删除或添加文件</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|-</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>| 执行 || x || 文件可以作为程序执行 || 进入到此目录(cd)</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>| 执行 || x <ins class="diffchange diffchange-inline">|| 1 </ins>|| 文件可以作为程序执行 || 进入到此目录(cd)</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|}</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>|}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></center></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></center></div></td></tr>
<tr><td colspan="2" class="diff-lineno">第27行:</td>
<td colspan="2" class="diff-lineno">第27行:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>===特殊权限===</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>===特殊权限===</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> 还有三种与用户身份无关的三个文件权限属性。 <del class="diffchange diffchange-inline">即SUID、SGID和Sticky </del>。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> 还有三种与用户身份无关的三个文件权限属性。 <ins class="diffchange diffchange-inline">即'''SUID'''、'''SGID'''和'''Sticky''' </ins>。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>;SUID(Set User ID):该属性只对有执行权限的文件有效,对目录无效。执行具有SUID权限的程序时,引发的进程的所有者是程序文件的所有者,而不是启动程序的用户(除非二者是同一个人)。比如,如果一个程序的所有者是root且具有SUID属性,一个普通用户执行此程序时,如同root执行此程序一样。<ref>http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/SetUserID.html</ref>'''请注意该属性对Shell脚本程序无效。'''该属性为一些特殊程序(如lpr)的启动带来了方便。但有时也带来了安全隐患:比如一个具有SUID属性的程序如果在执行时运行了一个shell,那么用户可以籍此得到系统的最高权限。SUID可用'''s'''表示。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>;SUID(Set User ID<ins class="diffchange diffchange-inline">, 4</ins>):该属性只对有执行权限的文件有效,对目录无效。执行具有SUID权限的程序时,引发的进程的所有者是程序文件的所有者,而不是启动程序的用户(除非二者是同一个人)。比如,如果一个程序的所有者是root且具有SUID属性,一个普通用户执行此程序时,如同root执行此程序一样。<ref>http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/SetUserID.html</ref>'''请注意该属性对Shell脚本程序无效。'''该属性为一些特殊程序(如lpr)的启动带来了方便。但有时也带来了安全隐患:比如一个具有SUID属性的程序如果在执行时运行了一个shell,那么用户可以籍此得到系统的最高权限。SUID可用'''s'''表示。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{{Hint|consolehelper是一个更高级的用于提供用户权限的解决方案,见[[使用consolehelper获得root权限]]。}}</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{{Hint|consolehelper是一个更高级的用于提供用户权限的解决方案,见[[使用consolehelper获得root权限]]。}}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>;SGID(Set Group ID):对于可执行文件,SGID与SUID类似,引发的进程的所有组是程序文件所属的组。对于目录,SGID属性会使目录中新建文件的所属组与该目录相同。SGID也可以用'''s'''表示。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>;SGID(Set Group ID<ins class="diffchange diffchange-inline">, 2</ins>):对于可执行文件,SGID与SUID类似,引发的进程的所有组是程序文件所属的组。对于目录,SGID属性会使目录中新建文件的所属组与该目录相同。SGID也可以用'''s'''表示。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>;Sticky:仅对目录有效。带sticky属性的目录下的文件或目录可以被其拥有者删除或改名。常利用sticky属性创建这样的目录:组用户可以在此目录中创建新文件、修改文件内容,但只有文件所有者才能对自己的文件进行删除或改名。如系统中的''/tmp''文件夹。在属性字符串中,通常用'''t'''表示。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>;Sticky<ins class="diffchange diffchange-inline">, 1</ins>:仅对目录有效。带sticky属性的目录下的文件或目录可以被其拥有者删除或改名。常利用sticky属性创建这样的目录:组用户可以在此目录中创建新文件、修改文件内容,但只有文件所有者才能对自己的文件进行删除或改名。如系统中的''/tmp''文件夹。在属性字符串中,通常用'''t'''表示。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{{Hint|最初sticky属性只可执行文件有效。正如其字面意思,它让具有sticky属性的可执行文件在执行结束后将程序代码仍滞留于内存中,以加快需要反复执行的大程序的装载速度。由于虚拟内存技术的引入,该功能已经没有意义。}}</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>{{Hint|最初sticky属性只可执行文件有效。正如其字面意思,它让具有sticky属性的可执行文件在执行结束后将程序代码仍滞留于内存中,以加快需要反复执行的大程序的装载速度。由于虚拟内存技术的引入,该功能已经没有意义。}}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>    </div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>    </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>==权限的表示==</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>==权限的表示==</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">===符号表示===</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 一个文件的权限可以用字符串直观的表示,使用''[[ls]] -l''命令可以看到表示权限的字符串。</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 一个文件的权限可以用字符串直观的表示,使用''[[ls]] -l''命令可以看到表示权限的字符串。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td colspan="2" class="diff-lineno">第49行:</td>
<td colspan="2" class="diff-lineno">第50行:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>  d<font color=blue>rwxrwxrwt</font> 12    root    root  16384 08-12 21:07 '''tmp'''</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>  d<font color=blue>rwxrwxrwt</font> 12    root    root  16384 08-12 21:07 '''tmp'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> 蓝色的部分就是权限字符串,权限表示三个为一组,依次是所有者权限、 <del class="diffchange diffchange-inline">所有 </del>组权限、其他人权限。每组的顺序均为rwx,如果有相应权限,则表示成相应字母,如果不具有相应权限,则用-表示。</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> 蓝色的部分就是权限字符串,权限表示三个为一组,依次是所有者权限、组权限、其他人权限。每组的顺序均为rwx,如果有相应权限,则表示成相应字母,如果不具有相应权限,则用-表示。</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 上面的例子中,第一行是一个普通文本文件,第二行是个普通的可执行程序,第三行是个普通的文件夹。第四行是带SUID、SGID的程序,最后一行则是''/tmp''的权限。</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div> 上面的例子中,第一行是一个普通文本文件,第二行是个普通的可执行程序,第三行是个普通的文件夹。第四行是带SUID、SGID的程序,最后一行则是''/tmp''的权限。</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">===数值表示===</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">为了简化表述,也可使用八进制数来表示权限。即用一个四位八进制数来表示,其中最高位表示特殊权限,随后的三位依次是所有者权限、组权限和其他人权限。每一个八进制位的权限数值是文件具有的相应权限所对应的数值之后,如:</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"> '''0755'''=rwxr-xr-x</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">而</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"> rw---x-w-=0(4+2)(1)(2)='''0612'''</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>==修改权限==</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>==修改权限==</div></td></tr>
</table>
Chenxing
http://linux-wiki.cn/index.php?title=%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90&diff=874&oldid=prev
Chenxing: 新页面: 出于安全的考虑,多用户操作系统需要具备保障个人隐私和系统安全的机制。在Linux中,这一机制主要表现为对文件访问权限的控制。<re...
2008-09-10T13:00:38Z
<p>新页面: 出于安全的考虑,<a href="/index.php?title=%E5%A4%9A%E7%94%A8%E6%88%B7%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F&action=edit&redlink=1" class="new" title="多用户操作系统(尚未撰写)">多用户操作系统</a>需要具备保障个人隐私和系统安全的机制。在<a href="/wiki/Linux" title="Linux">Linux</a>中,这一机制主要表现为对文件访问权限的控制。<re...</p>
<p><b>新建页面</b></p><div>出于安全的考虑,[[多用户操作系统]]需要具备保障个人隐私和系统安全的机制。在[[Linux]]中,这一机制主要表现为对文件访问权限的控制。<ref>http://linux.chinaitlab.com/administer/38992.html</ref><ref>http://doc.linuxpk.com/40848.html</ref><ref>http://blog.chinaunix.net/u2/71216/showart_734757.html</ref><br />
<br />
{{Hint|除了本文所讨论的内容之外,[[SELinux]](Security-Enhanced Linux)是另一种著名的安全机制,它是美国国家安全局(NAS)对于强制访问控制的实现,是一种更为可靠,也明显更为复杂的安全机制。在[[Fedora]]和[[Red Hat Enterprise Linux]]上默认安装了这一机制。}}<br />
<br />
==权限的定义==<br />
===基础权限===<br />
要确定一个用户对某个文件或目录是否具有相应的权限,先要明确该用户与文件或目录之间的关系。在Linux系统中,定义了如下三种关系:<br />
;文件所有者(owner):拥有文件的用户,通常是创建文件的用户。<br />
;组(group):文件所属的[[组]],通常是创建文件的用户所属的组。<br />
;其他人(other):既不是文件所有者,也不是文件所属的组的成员的其他用户。<br />
<br />
根据用户对文件或目录操作种类的不同,又定义了三种操作权限:<br />
<center><br />
{| class=wikitable<br />
|-<br />
!权限 !! 简写 !! 对普通文件的作用 !! 对文件夹的作用<br />
|-<br />
| 读取 || r || 查看文件内容 || 列出目录中的文件(ls)<br />
|-<br />
| 写入 || w || 修改文件内容 || 在目录中删除或添加文件<br />
|-<br />
| 执行 || x || 文件可以作为程序执行 || 进入到此目录(cd)<br />
|}<br />
</center><br />
<br />
上面的三种关系与三种操作权限的组合,构成了一个含有9个二进制位的权限标识。<br />
<br />
===特殊权限===<br />
还有三种与用户身份无关的三个文件权限属性。即SUID、SGID和Sticky。<br />
<br />
;SUID(Set User ID):该属性只对有执行权限的文件有效,对目录无效。执行具有SUID权限的程序时,引发的进程的所有者是程序文件的所有者,而不是启动程序的用户(除非二者是同一个人)。比如,如果一个程序的所有者是root且具有SUID属性,一个普通用户执行此程序时,如同root执行此程序一样。<ref>http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/SetUserID.html</ref>'''请注意该属性对Shell脚本程序无效。'''该属性为一些特殊程序(如lpr)的启动带来了方便。但有时也带来了安全隐患:比如一个具有SUID属性的程序如果在执行时运行了一个shell,那么用户可以籍此得到系统的最高权限。SUID可用'''s'''表示。<br />
<br />
{{Hint|consolehelper是一个更高级的用于提供用户权限的解决方案,见[[使用consolehelper获得root权限]]。}}<br />
<br />
;SGID(Set Group ID):对于可执行文件,SGID与SUID类似,引发的进程的所有组是程序文件所属的组。对于目录,SGID属性会使目录中新建文件的所属组与该目录相同。SGID也可以用'''s'''表示。<br />
<br />
;Sticky:仅对目录有效。带sticky属性的目录下的文件或目录可以被其拥有者删除或改名。常利用sticky属性创建这样的目录:组用户可以在此目录中创建新文件、修改文件内容,但只有文件所有者才能对自己的文件进行删除或改名。如系统中的''/tmp''文件夹。在属性字符串中,通常用'''t'''表示。<br />
<br />
{{Hint|最初sticky属性只可执行文件有效。正如其字面意思,它让具有sticky属性的可执行文件在执行结束后将程序代码仍滞留于内存中,以加快需要反复执行的大程序的装载速度。由于虚拟内存技术的引入,该功能已经没有意义。}}<br />
<br />
==权限的表示==<br />
一个文件的权限可以用字符串直观的表示,使用''[[ls]] -l''命令可以看到表示权限的字符串。<br />
<br />
下面来看几个例子:<br />
-<font color=blue>rw-r--r--</font> 1 gnixnehc gnixnehc 131 08-12 13:22 '''normal_text'''<br />
-<font color=blue>rwxr-xr-x</font> 1 gnixnehc gnixnehc 6809 08-12 13:22 '''normal_exe'''<br />
d<font color=blue>rwxr-xr-x</font> 2 gnixnehc gnixnehc 4096 07-03 01:13 '''normal_dir'''<br />
-<font color=blue>rwsr-sr-x</font> 1 gnixnehc gnixnehc 6809 08-12 13:22 '''suid_exe'''<br />
d<font color=blue>rwxrwxrwt</font> 12 root root 16384 08-12 21:07 '''tmp'''<br />
<br />
蓝色的部分就是权限字符串,权限表示三个为一组,依次是所有者权限、所有组权限、其他人权限。每组的顺序均为rwx,如果有相应权限,则表示成相应字母,如果不具有相应权限,则用-表示。<br />
<br />
上面的例子中,第一行是一个普通文本文件,第二行是个普通的可执行程序,第三行是个普通的文件夹。第四行是带SUID、SGID的程序,最后一行则是''/tmp''的权限。<br />
<br />
==修改权限==<br />
文件所有者或超级用户可以修改一个文件的权限。<br />
<br />
可以使用[[chmod]]修改文件或目录的权限,也可以使用桌面环境的文件管理程序修改权限。<br />
<br />
==参考资料==<br />
<references /></div>
Chenxing