Git 服務器 Gitosis 架設指南
Git是非常著名的分布式版本控制系統。
Gitosis則是方便通過Git與ssh架設中央服務器的軟件。這篇文章的安裝流程寫得很明了,但使用中還是遇到了些許問題,本文算是該流程的補充。如果打算通過Gitosis架設服務器通過本文或許可以少走不少彎路。
一、架設步驟
1. 下載并安裝python setuptools
sudo apt-get install python-setuptools2. 下載并安裝gitosis
cd ~/srcgit clone git://eagain.net/gitosis.git
cd gitosis
python setup.py install
3. 添加用戶git
sudo adduser \ --system \ --shell /bin/sh \ --gecos 'git version control' \ --group \ --disabled-password \ --home /home/git \ git
4. 生成本機密鑰
切換到個人機,如果已有~/.ssh/id_rsa.pub略過此步ssh-keygen -t rsa
5. 上傳密鑰到服務器臨時目錄
scp ~/.ssh/id_rsa.pub 用戶名@主機:/tmp6. 初使化gitosis
切回到服務器sudo -H -u git gitosis-init < /tmp/id_rsa.pub
7. 修改post-update權限
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update8. clone gitosis管理平臺
git clone git@主機名:gitosis-admin.gitcd gitosis-admin
9. 安裝完成
通過修改gitosis-admin管理gitosis用戶權限添加公密到keydir,添加用戶
修改完后commit,push到中服務器即可完成倉庫權限的相關操作。
二、實例
目標:添加用戶 john 和倉庫 foo 到gitosis,并和管理員miao合作管理1. 用戶john添加并發送id_rsa.pub給miao
- john:~$ ssh-keygen -t rsa
- Generating public/private rsa key pair.
Enter file in which to save the key (/home/john/.ssh/id_rsa):
Created directory '/home/john/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/john/.ssh/id_rsa.
Your public key has been saved in /home/john/.ssh/id_rsa.pub.
- john:~$ cp /home/john/.ssh/id_rsa.pub /tmp
2. gitosis管理員miao分配john權限
- miao:~$ cd ~/projects
- git clone git@192.168.1.115:gitosis-admin
- cd gitosis-admin
- cat gitosis.conf
-
[gitosis]
[group gitosis-admin] writable = gitosis-admin members = miao@u32-192-168-1-110</pre></div> </dd>
- ls keydir/
- miao@u32-192-168-1-110.pub
- cp /tmp/id_rsa.pub keydir/john.pub
- vi gitosis.conf
[gitosis]
[group gitosis-admin] writable = gitosis-admin members = miao@u32-192-168-1-110
[group foo] writable = foo members = miao@u32-192-168-1-110 john</pre></div> </dd>
- git add .
- git commit -am "add member john and project foo"
- git push
</dl>3. 用戶 miao 添加項目foo
- miao:~$ cd ~/projects
- mkdir foo
- cd foo
- git init
- touch hello.txt
- git add hello.txt
- git commit -am 'first commit'
- git remote add origin git@192.168.1.115:foo.git
- git push origin master
4. 用戶 john clone Foo并修改hello.txt
- john:~$ git clone git@192.168.1.115:foo.git
- cd foo
- ls
- date > hello.txt
- git commit -am 'add time to hello.txt' && git push
5. 用戶 miao pull Foo
- miao:~/projects/foo$ vi .git/config
-
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = git@192.168.1.115:foo.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master
- git pull
三、常見問題
首先確定 /home/git/repositories/gitosis-admin.git/hooks/post-update 為可執行即屬性為 07551. git操作需要輸入密碼
- 原因
- 公密未找到
- 解決
- 上傳id_pub.rsa到keydir并改為'gitosis帳號.pub'形式,如miao.pub。擴展名.pub不可省略
2. ERROR:gitosis.serve.main:Repository read access denied
- 原因
- gitosis.conf中的members與keydir中的用戶名不一致,如gitosis中的members = foo@bar,但keydir中的公密名卻叫foo.pub
- 解決
- 使keydir的名稱與gitosis中members所指的名稱一致。
改為members = foo 或 公密名稱改為foo@bar.pub
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!相關資訊