簡體中文 ▾ 主題 ▾ 最新版本 ▾ git-shell 上次更新於 2.18.0

名稱

git-shell - 用於 Git 專用 SSH 訪問的受限登入 Shell

概要

chsh -s $(command -v git-shell) <user>
git clone <user>@localhost:/path/to/repo.git
ssh <user>@localhost

描述

這是一個用於 SSH 賬戶的登入 Shell,提供受限的 Git 訪問。它只允許執行實現拉取/推送功能的伺服器端 Git 命令,以及使用者主目錄中名為 git-shell-commands 的子目錄中存在的自定義命令。

命令

git shell-c 選項後接受以下命令

git receive-pack <引數>
git upload-pack <引數>
git upload-archive <引數>

呼叫相應的伺服器端命令以支援客戶端的 git pushgit fetchgit archive --remote 請求。

cvs server

模擬 CVS 伺服器。請參閱 git-cvsserver[1]

如果存在 ~/git-shell-commands 目錄,git shell 還會透過從使用者主目錄執行 "git-shell-commands/<命令> <引數>" 來處理其他自定義命令。

互動式使用

預設情況下,上述命令只能使用 -c 選項執行;Shell 不是互動式的。

如果存在 ~/git-shell-commands 目錄,git shell 也可以互動式執行(不帶引數)。如果 git-shell-commands 目錄中存在 help 命令,則會執行該命令,為使用者提供允許操作的概述。然後會顯示一個 "git> " 提示符,您可以在其中輸入 git-shell-commands 目錄中的任何命令,或者輸入 exit 來關閉連線。

通常,此模式用作管理介面,允許使用者列出他們有權訪問的倉庫,建立、刪除或重新命名倉庫,或更改倉庫描述和許可權。

如果存在 no-interactive-login 命令,則會執行該命令並中止互動式 Shell。

示例

停用互動式登入,顯示問候語

$ chsh -s /usr/bin/git-shell
$ mkdir $HOME/git-shell-commands
$ cat >$HOME/git-shell-commands/no-interactive-login <<\EOF
#!/bin/sh
printf '%s\n' "Hi $USER! You've successfully authenticated, but I do not"
printf '%s\n' "provide interactive shell access."
exit 128
EOF
$ chmod +x $HOME/git-shell-commands/no-interactive-login

啟用 git-cvsserver 訪問(這通常需要上述 no-interactive-login 示例作為先決條件,因為建立 git-shell-commands 目錄允許互動式登入)

$ cat >$HOME/git-shell-commands/cvs <<\EOF
if ! test $# = 1 && test "$1" = "server"
then
	echo >&2 "git-cvsserver only handles \"server\""
	exit 1
fi
exec git cvsserver server
EOF
$ chmod +x $HOME/git-shell-commands/cvs

另請參閱

ssh(1), git-daemon[1], contrib/git-shell-commands/README

GIT

Git[1] 套件的一部分