雖然 git 可以利用 ssh + ssh key 來變成不能密碼就能 clone

但想想, 這樣子好像不是很對耶, 有幾點的考慮

1. 要是 client 是在一個自己覺得不安全的環境, 又要讓它能直接利用 key 登入 remote 端拿資料, 鳥鳥的

2. 要是不用 key 的話, 若 git clone or git pull 都要打密碼, 更鳥 @@ (我很懶)

3. 因為我的 .tcshrc 是有自己寫自動判斷是不是要更新 cvs tree, 以前用 svn 是走 svn://, 現在改 git 走的是 ssh, 變成每次要自動 git pull 都要打密碼, 鳥鳥鳥

經過以上的想法, 決定用 git server 了

而 FreeBSD 安裝完後, 就有 git-daemon, 有點類似 svn server 的功能

在網路上找了一堆文章, 大家都是要 git + http + git account 來達成, 看來看去, 一樣一整個鳥

後來參考這篇, 主要是裡面的一些指令, 借來用

再東看西看以下的

https://git.wiki.kernel.org/index.php/GitFaq#How_to_set_up_a_git_server.3F

http://www.kernel.org/pub/software/scm/git/docs/everyday.html#Repository%20Administration

總合出我自己的方法, 不用開 git account, 也不用做 gitweb or apache (http) 等, 就是很單純的 git server

1. 安裝 git

cd /usr/ports/devel/git
make config

Options 我只選 CONTRIB P4 ICONV CURL ETCSHELLS, 和系統內定有一點點差別, 若是和我不一樣的, 請自己測試

make install clean

2. 編輯 /etc/rc.conf

git_daemon_enable="YES"
git_daemon_directory="/path/to/gitroot"
git_daemon_flags="--verbose --export-all --syslog --reuseaddr --enable=receive-pack --base-path=/path/to/gitroot --detach"

ps. /path/to/gitroot 是 gitroot 的目錄, 而不是真的目錄, Ex: 若 gitroot 在 /home/gitroot, 則 /path/to/gitroot = /home/gitroot

3. 設定 repository for git

mkdir -p /path/to/gitroot/test.git
cd /path/to/gitroot/test.git
git init --bare

4. 建立 client 用的 git repo

cd /tmp/test.git
git init (之前忘了加, 所以會有問題)
touch a
git add a
git commit -m 'first commit'

5. 和 remote 同步

git remote add origin git://server_hostname_or_ip_address/test.git
git push origin master

以上就成功了

6. 測試

mkdir /tmp/test2
git clone git://server_hostname_or_ip_address/test.git

就可以把 server 上的 test.git clone 下來, 很方便

7. 資安想法
請記得把 9418 檔好, 不管是用什麼方法, 請用自己熟的方法檔起來
當然要是認真一點, 可以利用 git 裡面的 config 去設定, 但我懶, 就用 ipfw 去封就好

以上

git remote server

One thought on “git remote server

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料

Verified by MonsterInsights