2019-04-21 11:50:48 +08:00

25 lines
1.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1 id="su">su</h1>
<p>用于切换当前用户身份到其他用户身份</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>su命令</strong> 用于切换当前用户身份到其他用户身份,变更时须输入所要变更的用户帐号与密码。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">su(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-c&lt;指令&gt;或--command=&lt;指令&gt;:执行完指定的指令后,即恢复原来的身份;
-f或——fast适用于csh与tsch使shell不用去读取启动文件
-l或——login改变身份时也同时变更工作目录以及HOME,SHELL,USER,logname。此外也会变更PATH变量
-m,-p或--preserve-environment变更身份时不要变更环境变量
-s&lt;shell&gt;或--shell=&lt;shell&gt;指定要执行的shell
--help显示帮助
--version显示版本信息。</code></pre>
<h3 id="参数">参数</h3>
<p>用户:指定要切换身份的目标用户。</p>
<h3 id="实例">实例</h3>
<p>变更帐号为root并在执行ls指令后退出变回原使用者</p>
<pre><code class="language-bash">su -c ls root</code></pre>
<p>变更帐号为root并传入<code>-f</code>选项给新执行的shell</p>
<pre><code class="language-bash">su root -f</code></pre>
<p>变更帐号为test并改变工作目录至test的家目录</p>
<pre><code class="language-bash">su -test</code></pre>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->