配置簡單的Git服務器

服務端
1、安裝GIT
[iong@bogon iong]# sudo apt-get install git

2、創建git用戶,並設置密碼
[iong@bogon iong]# sudo adduser git
[iong@bogon iong]# sudo -s
[root@bogon iong]# passwd git

3、創建GIt倉庫目錄

[root@bogon iong]# mkdir /git
[root@bogon iong]# cd /git/

4、初始化倉庫,並將倉庫所有者更改爲git
[root@bogon git]# git init --bare sample.git
初始化空的 Git 版本庫於 /git/sample.git/
[root@bogon git]# chown -R git:git /git

5、使用root用戶在Git服務中添加客戶端密鑰

[iong@bogon iong]# sudo -s
[root@bogon git]# mkdir /home/git/.ssh
[root@bogon git]# touch /home/git/.ssh/authorized_keys
[root@bogon git]# vi /home/git/.ssh/authorized_keys

將所有的客戶端的id_rsa.pub生成的公鑰複製到 authorized_keys 文件裏
6、禁用git用戶sell權限
這可以通過編輯/etc/passwd文件完成。找到類似下面的一行:
git:x:1001:1001:,,,:/home/git:/bin/bash
改爲:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell

客戶端

1、使用賬戶生成ssh密鑰
[iong@bogon git]$ su iong
[iong@bogon git]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/iong/.ssh/id_rsa):
Created directory '/home/iong/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/iong/.ssh/id_rsa.
Your public key has been saved in /home/iong/.ssh/id_rsa.pub.
The key fingerprint is:
6a:e9:f1:2f:86:47:76:ea:c3:b2:64:c9:35:7a:4c:ac iong@bogon
The key's randomart image is:

密鑰生成在/home/iong/.ssh/id_rsa.pub文件中
2、第一次提交需要設置郵箱和用戶
[iong@bogon abctime]$ git config --global user.email "[email protected]"
[iong@bogon abctime]$ git config --global user.name "li"

3、 在項目中初始化Git,並提交版本
[iong@bogon abctime]$ git init
[iong@bogon abctime]$ git add ./*
[iong@bogon abctime]$ git commit -m 'v1.0'

4、關聯遠程倉庫
[iong@bogon abctime]$ sudo git remote add origin [email protected]:/git/sample.git
5、將本地項目提交到遠程倉庫
[iong@bogon abctime]$ git push -u origin master
6、其他客戶端直接下載Git庫至本地,可能需要提供git賬號的密碼
git clone git@*.*.*.*:/git/sample.git

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章