mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-08 15:04:05 +08:00
37 lines
2.8 KiB
HTML
37 lines
2.8 KiB
HTML
<h1 id="chcon">chcon</h1>
|
||
<p>修改对象(文件)的安全上下文</p>
|
||
<h2 id="补充说明">补充说明</h2>
|
||
<p><strong>chcon命令</strong> 是修改对象(文件)的安全上下文,比如:用户、角色、类型、安全级别。也就是将每个文件的安全环境变更至指定环境。使用<code>--reference</code>选项时,把指定文件的安全环境设置为与参考文件相同。chcon命令位于<code>/usr/bin/chcon</code>。</p>
|
||
<h3 id="语法">语法</h3>
|
||
<pre><code class="language-bash">chcon [选项]... 环境 文件...
|
||
chcon [选项]... [-u 用户] [-r 角色] [-l 范围] [-t 类型] 文件...
|
||
chcon [选项]... --reference=参考文件 文件...</code></pre>
|
||
<h3 id="选项">选项</h3>
|
||
<pre><code class="language-bash">-h, --no-dereference:影响符号连接而非引用的文件。
|
||
--reference=参考文件:使用指定参考文件的安全环境,而非指定值。
|
||
-R, --recursive:递归处理所有的文件及子目录。
|
||
-v, --verbose:为处理的所有文件显示诊断信息。
|
||
-u, --user=用户:设置指定用户的目标安全环境。
|
||
-r, --role=角色:设置指定角色的目标安全环境。
|
||
-t, --type=类型:设置指定类型的目标安全环境。
|
||
-l, --range=范围:设置指定范围的目标安全环境。</code></pre>
|
||
<p>以下选项是在指定了<code>-R</code>选项时被用于设置如何穿越目录结构体系。如果您指定了多于一个选项,那么只有最后一个会生效。</p>
|
||
<pre><code class="language-bash">-H:如果命令行参数是一个通到目录的符号链接,则遍历符号链接。
|
||
-L:遍历每一个遇到的通到目录的符号链接。
|
||
-P:不遍历任何符号链接(默认)。
|
||
--help:显示此帮助信息并退出。
|
||
--version:显示版本信息并退出。</code></pre>
|
||
<h3 id="实例">实例</h3>
|
||
<p>如果你想把这个ftp共享给匿名用户的话,需要开启以下:</p>
|
||
<pre><code class="language-bash">chcon -R -t public_content_t /var/ftp</code></pre>
|
||
<p>如果你想让你设置的FTP目录可以上传文件的话,SELINUX需要设置:</p>
|
||
<pre><code class="language-bash">chcon -t public_content_rw_t /var/ftp/incoming</code></pre>
|
||
<p>允许用户HHTP访问其家目录,该设定限仅于用户的家目录主页:</p>
|
||
<pre><code class="language-bash">setsebool -P httpd_enable_homedirs 1
|
||
chcon -R -t httpd_sys_content_t ~user/public_html</code></pre>
|
||
<p>如果你希望将samba目录共享给其他用户,你需要设置:</p>
|
||
<pre><code class="language-bash">chcon -t samba_share_t /directory</code></pre>
|
||
<p>共享rsync目录时:</p>
|
||
<pre><code class="language-bash">chcon -t public_content_t /directories</code></pre>
|
||
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->
|