安裝 git 及 gitosis
$ sudo apt-get install gitosis git-core
在 Client 端電腦生成 SSH公鑰並上傳至Server端
$ ssh-keygen -t rsa
(生成出來的key,預設是放在 ~/.ssh/下面)
$ scp ~/.ssh/id_rsa.pub serverIP:/tmp/id_rsa_user.pub
初使化gitosis
在client端電腦連線至server端
$ ssh account@serviceIP
$ sudo -H -u gitosis gitosis-init < /tmp/id_rsa_user.pub
(因為目前只有一位使用者,所以將他設為admin權限)
完成後若出現下列訊息,即代表成功
Initialized empty Git repository in /srv/gitosis/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /srv/gitosis/repositories/gitosis-admin.git/
修改執行權限
$ sudo chmod 755 /srv/gitosis/repositories/gitosis-admin.git/hooks/post-update
設定專案權限、新增帳號
$ git clone gitosis@serviceIP:gitosis-admin.git
抓下來後可以看到,主要分成兩個部份
gitosis.conf
keydir/
接下來將使用者的public key複製到 keydir下面,再新增 git 帳號
$ cp /tmp/id_rsa_user2.pub keydir/user2.pub
$ git add keydir/user2.pub
$ git commit -m 'add user2'
$ git push
$vi gitosis.conf
可以看見預設的管理員權限
[group gitosis-admin]
writable = gitosis-admin
members = admin@example.com
若要新增一個 project,可以輸入
[group project_team_name]
writable = project_name
member = user_name
$ git commit -m 'create a new project and add user2'
$ git push
(這裡的 user_name必需與剛才所加的 .pub 名稱是一致的才行)
建立新專案
$ mkdir project_name
$ cd project_name
$ git init
$ git remote add origin gitosis@serverIP:project_name.git
$ git add.
$ git commit
$ git push origin master
沒有留言:
張貼留言