BV1AL 之無所不記

2010-02-04

限制 user 只能 git 不能進機組亂逛, 以及透過 tor 來 git

git server 使用ssh protocol 時,不想讓user 進機組亂逛,只讓user 可以
git pull/push, 怎麼辦?

很簡單!不要往 sshd 往 chroot 往 rbash 那些方向想,因為那太費事了。

Torvalds 大神早就想到、做好了!

請直接把該user 的login shell 從system default 的/bin/bash 換成 /usr/bin/git-shell
一切就搞定。(user 便不能ssh 或sftp 進機組)

然後以root 身份到user $HOME mkdir 一個git dir 再做git 最基本的 init add commit
完成後記得 chown -R user_id.user_id 這個dir, 然後請user 第一次以clone 抓回去
往後就可以修改再push 回git server 了.

可以將user 這個git dir link 到system git 下, 便可以讓任何人以git protocol
直接clone 抓回去用了.

?? 忽然想到git 如何透過tor pull/push ??

找到這一篇 http://threebytesfull.com/2008/04/git-with-and-without-proxy/

但是當自行跑tor 時port 不同, 要將 1080 改成 9050
基本做法就是要設定 GIT_SSH 跟 GIT_PROXY_COMMAND 這兩個環境變數

首先在path 的$HOME/bin/下建立第一個 script, 名子例如叫 tor-ssh 內容有三行
export GIT_SSH="${HOME}/bin/socks-ssh"
export GIT_PROXY_COMMAND="$HOME/bin/socks-gw"
$@

不過可以在起頭加上提示如何使用參數
if [ "$1x" == "x" ]; then
echo "$0 git command ssh://ID@host/path/GIT"
exit 1
fi

接下來建立 socks-ssh 內容是
ssh -o ProxyCommand="$HOME/bin/socks-gw %h %p" $@

以及另一個 socks-gw 內容是
/usr/bin/connect -4 -S localhost:9050 $@
(該作者用的proxy port 是1080)

這樣如果要透過 tor 來git 就是下令
tor-ssh git command options
不透過tor 的話就是
git command options

標籤:

1 Comments:

張貼留言

<< Home