歡迎您光臨本站 註冊首頁

純用SSH管理GIT伺服器

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

純用SSH管理GIT伺服器


純用SSH管理GIT伺服器


gitosis等管理git伺服器有點小複雜,一般小規模開發沒必要用,僅僅依靠Linux的SSH就可以管理了。步驟如下


1 添加用戶,並準備公鑰私鑰

添加用戶git,密碼也是git

adduser danny
passwd danny
adduser git
passwd git

root用產生公鑰在/root/.ssh/id_rsa下面

ssh-keygen -t rsa

然後分別su danny / su git,同樣執行

ssh-keygen -t rsa  

回到root下執行

cp /home/danny/.ssh/id_rsa.pub /home/git/.ssh/danny_rsa.pub

cd /home/git/.ssh/

cat danny_rsa.pub >> authorized_keys

cat authorized_keys

rm -rf danny_rsa.pub

chown git authorized_keys

mkdir /home/git/repos

chown -R git /home/git/repos

2 建立測試項目

切換到git用戶,進入git主目錄,建立testproject.git

su git

cd ~

mkdir /home/git/repos/testproject.git

cd /home/git/repos/testproject.git

初始化git庫
git init

設置用戶
git config user.email "git@xxx.cn"
git config user.name "git"


在該目錄下建立一個test文件,並提交。
vi test

git add test

git add --all 添加所有待添加文件

git commit -a -m "add test"

創建分支,默認的master分支,不允許其他用戶提交
git branch develop
查看分支
git branch
切換分支
git checkout develop



3 克隆測試項目

切換到danny用戶,進入danny的主目錄

su danny

cd ~

git clone git@localhost:/home/git/testproject.git

cd testproject.git

設置用戶
git config user.email "danny@xxx.com"
git config user.name "danny"


在該目錄下建立一個test文件,並提交。注意此時只是提交到danny目錄下的庫,並沒有提交到git用戶目錄下的庫。
vi test

git add test2

git commit -a -m "add test2"

4 在windows下,使用TortoiseGit連接

在管理員windows機器上通過mysygit的bash命令生成公鑰,私鑰;在 C:\Documents and Settings\Administrator\.ssh 目錄下

ssh-keygen -t rsa

使用 D:\Program Files\TortoiseGit\bin\puttygen.exe,存為putty專用格式

"Load" Administrator\.ssh 目錄下的id_rsa

"Save private kay" putty.ppk

同時將公鑰中的那行複製到git/.ssh/authorized_keys中

使用TortoiseGit clone一個項目

ssh://git@172.20.x.x/home/git/testproject.git

勾上Load Putty key "C:\Documents and Settings\Administrator\.ssh\putty.ppk"



日常操作時

git pull,git pull develop
解決有沒有更新衝突
git push,git push develop
《解決方案》

謝謝分享

[火星人 ] 純用SSH管理GIT伺服器已經有1153次圍觀

http://coctec.com/docs/service/show-post-1142.html