uTools-Manuals/docs/git/git shell.html
2019-05-07 10:40:55 +08:00

12 lines
4.5 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

<div class="c-markdown doc-markdown"><div class="doc-postil"><div class="c-markdown"><h2>名称</h2></div></div><div class="doc-postil"><div class="c-markdown"><p>git-shell  - 仅限 Git-SSH 访问的受限登录 shell</p></div></div><div class="doc-postil"><div class="c-markdown"><h2>概要</h2></div></div><div class="doc-postil"><div class="c-markdown"><pre><code class="language-Bash">chsh -s $(command -v git-shell) &lt;user&gt;git clone &lt;user&gt;@localhost:/path/to/repo.git
ssh &lt;user&gt;@localhost</code></pre></div></div><div class="doc-postil"><div class="c-markdown"><h2>描述</h2></div></div><div class="doc-postil"><div class="c-markdown"><p>这是 SSH 帐户的登录外壳,用于提供受限制的 Git 访问。它只允许执行实现拉/推功能的服务器端 Git 命令,以及<code>git-shell-commands</code>在用户主目录中命名的子目录中存在的自定义命令。</p></div></div><div class="doc-postil"><div class="c-markdown"><h2>命令</h2></div></div><div class="doc-postil"><div class="c-markdown"><p><code>git shell</code><code>-c</code>选项后接受以下命令:</p></div></div><div class="doc-postil"><div class="c-markdown"><p><em style="font-style: italic;">git receive-pack &lt;argument&gt;</em>   <em style="font-style: italic;">git upload-pack &lt;argument&gt;</em>   <em style="font-style: italic;">git upload-archive &lt;argument&gt;</em></p></div></div><div class="doc-postil"><div class="c-markdown"><p>调用相应的服务器端命令,以支持客户端的<code>git push</code><code>git fetch</code><code>git archive --remote</code>请求。</p></div></div><div class="doc-postil"><div class="c-markdown"><p><em style="font-style: italic;">cvs server</em></p></div></div><div class="doc-postil"><div class="c-markdown"><p>模仿 CVS 服务器。参见 git-cvsserver [1]。</p></div></div><div class="doc-postil"><div class="c-markdown"><p>如果存在<code>~/git-shell-commands</code>目录,则<code>git shell</code>还将通过在用户的主目录中运行“ <code>git-shell-commands/&lt;command&gt; &lt;arguments&gt;</code>”来处理其他自定义命令。</p></div></div><div class="doc-postil"><div class="c-markdown"><h2>交互式使用</h2></div></div><div class="doc-postil"><div class="c-markdown"><p>默认情况下,上述命令只能使用该<code>-c</code>选项执行; 该 shell 不是交互式的。</p></div></div><div class="doc-postil"><div class="c-markdown"><p>如果<code>~/git-shell-commands</code>目录存在,<code>git shell</code>也可以交互式运行(不带参数)。如果目录中<code>help</code>存在命令<code>git-shell-commands</code>则会向用户提供允许的操作概述。然后出现一个“git&gt;”提示符,用户可以输入<code>git-shell-commands</code>目录中的任何命令或<code>exit</code>关闭连接。</p></div></div><div class="doc-postil"><div class="c-markdown"><p>通常,此模式用作管理界面,以允许用户列出他们有权访问的存储库,创建,删除或重命名存储库,或更改存储库描述和权限。</p></div></div><div class="doc-postil"><div class="c-markdown"><p>如果<code>no-interactive-login</code>命令存在,则运行它并交互式 shell 被中止。</p></div></div><div class="doc-postil"><div class="c-markdown"><h2>示例</h2></div></div><div class="doc-postil"><div class="c-markdown"><p>To disable interactive logins, displaying a greeting instead:</p></div></div><div class="doc-postil"><div class="c-markdown"><pre><code class="language-Bash">$ chsh -s /usr/bin/git-shell
$ mkdir $HOME/git-shell-commands
$ cat &gt;$HOME/git-shell-commands/no-interactive-login &lt;&lt;\EOF
#!/bin/sh
printf '%s\n' "Hi $USER! You've successfully authenticated, but I do not"printf '%s\n' "provide interactive shell access."exit 128EOF
$ chmod +x $HOME/git-shell-commands/no-interactive-login</code></pre></div></div><div class="doc-postil"><div class="c-markdown"><p>要启用 git-cvsserver 访问权限(通常应该有上述<code>no-interactive-login</code>示例作为先决条件,因为创建 git-shell-commands 目录允许交互式登录):</p></div></div><div class="doc-postil"><div class="c-markdown"><pre><code class="language-Bash">$ cat &gt;$HOME/git-shell-commands/cvs &lt;&lt;\EOFif ! test $# = 1 &amp;&amp; test "$1" = "server"then
        echo &gt;&amp;2 "git-cvsserver only handles \"server\""
        exit 1fi
exec git cvsserver server
EOF
$ chmod +x $HOME/git-shell-commands/cvs</code></pre></div></div></div>