Git/Gitosis
Gitosis 是一種工具,用於保護集中式的 Git 倉庫,允許多個維護者同時管理同一個專案,透過限制對只通過安全網路協議的訪問來實現。
要安裝 Gitosis,您首先必須安裝 Git 客戶端。安裝完成後,從其倉庫簽出一個 Gitosis 的副本
git clone git://eagain.net/gitosis.git
安裝
cd gitosis python setup.py install
建立一個使用者來管理倉庫
sudo adduser \ --system \ --shell /bin/sh \ --gecos 'git version control' \ --group \ --disabled-password \ --home /home/git \ git
如果您還沒有公鑰,請在您的本地計算機上建立一個
ssh-keygen -t rsa
將此金鑰複製到 Gitosis 伺服器。假設您在您的主目錄中
scp .ssh/id_rsa.pub user@example.com:/tmp
初始化 Gitosis
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
成功後,您將看到
Initialized empty Git repository in ./ Initialized empty Git repository in ./
確保 Git post-update hook 具有正確的許可權
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
Gitosis 建立了它自己的 Git 倉庫。要配置 Gitosis,您需要克隆這個倉庫,設定您的配置選項,然後將您的配置推送到 Gitosis 伺服器。
克隆 Gitosis 倉庫
git clone git@example.com:gitosis-admin.git cd gitosis-admin
編輯 gitosis.conf
一個預設 gitosis.conf 的示例
[gitosis]
[group gitosis-admin] writable = gitosis-admin members = jdoe
您可以像這樣定義成員組以及他們對倉庫的許可權
[group blue_team] members = john martin stephen writable = tea_timer coffee_maker
在這個例子中,blue_team 組中的任何成員,在本例中是 john、martin 和 stephen,都將可以寫入 tea_timer 和 coffee_maker Git 倉庫
儲存、提交併推送此檔案。
git commit -am "Give john, martin, and stephen access to the repositories tea_timer and coffee_maker." git push
接下來,建立一個倉庫。您需要先切換到您要儲存 Git 倉庫本地副本的目錄。
建立倉庫
mkdir tea_timer cd tea_timer git init git remote add origin git@example.com:tea_timer.git # Add some files and commit. git push origin master:refs/heads/master # The previous line links your local branch master to the remote branch master so you can automatically fetch and merge with git pull.
使用者透過他們的公鑰來標識。Gitosis 將這些金鑰儲存在 gitosis-admin 倉庫的 keydir 目錄中。使用者透過金鑰檔案的名稱與其 Git 使用者名稱相關聯。例如,將一個 RSA 金鑰新增到 keydir/john.pub 將會將使用者 john 與 john.pub 中定義的機器相關聯。金鑰必須以 .pub 結尾!
新增使用者
cd gitosis-admin cp /path/to/rsa/key/john.pub keydir/ git add keydir/* git commit -am "Adding the john account." git push
John 現在可以克隆他可以訪問的 Git 倉庫,這些倉庫由 gitosis.conf 定義。在本例中,他可以讀取和寫入倉庫,因為他擁有 writable 許可權。