Windows(cygwin)で、SSH, Subversion, Git サーバを立てる
Windows(cygwin)で、SSH, Subversion, gitosis(Git)サーバを立てるときに、色々調べたのでメモ
cygwin install
setup.exeを実行。
cygrunsrv, openssh, git, python などを入れる。お好みで subversion, vim, emacs なども。
sshサーバ
以下のサイトが参考になった
- http://www.uechan.com/yeti/tips4.html
- http://new.micro-vnc.jp/documents/archieve/sshwindows/
- http://www.rouge.gr.jp/~fuku/tips/cygwin-sshd/
Windowsの環境変数 CYGWIN = binmode ntsec tty を設定。
cygwin上で
$ mkpasswd -l > /etc/passwd $ mkgroup -l > /etc/group $ chmod +r /etc/passwd $ chmod +r /etc/group $ chmod 111 /var $ ssh-host-config
全部yesでOKっぽい?
CYGWIN環境変数は、上記の通りに。
/etc/sshd_config も編集。公開鍵ログインのみに
Port 22 (変更するのもアリ) Protocol 2 PermitRootLogin no PasswordAuthentication no PermitEmptyPasswords no X11Forwarding no ChallengeResponseAuthentication no StrictModes yes PubkeyAuthentication yes
サービス起動
コマンドプロンプト> net start sshd
subversonサーバ
このへんを参考に。cygwin版ではなく、Tigris.orgのWindows版のsvnでいけた。
Windows上で、subverson用のアカウント(例えばsvnuser)を作った後、cygwin上にもアカウントを作成
$ mkpasswd -l -u svnuser >> /etc/passwd
svnuserでcygwinにログイン
コマンドプロンプト> runas /user:svnuser C:/cygwin/cygwin.bat
svnuserの authorized_keys を編集。公開鍵の前に、svnserveコマンドを挿入する
command="svnserve.exeへのパス -t -r リポジトリパス --tunnel-user=svnuser",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa 公開鍵...
authorized_keysのパーミッションにも注意
$ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/authorized_keys
gitosis(Gitサーバ)
以下のサイトが参考になる
- http://www.markembling.info/view/git-server-gitosis-and-cygwin-on-windows
- http://openbooth.org/archives/60.html
http://pypi.python.org/pypi/setuptools から、setuptools-0.xxx-py2.5.egg とかを入手し、
$ chmod 755 ./setuptools-0.xxx-py2.5.egg $ ./setuptools-0.xxx-py2.5.egg $ git clone git://eagain.net/gitosis.git $ cd gitosis $ python setup.py install
Windows上で、"git"という名前のユーザ(gitosis用の共用アカウント)を作った後、cygwin上にもアカウントを作成
$ mkpasswd -l -u git >> /etc/passwd
あらかじめ、管理者の公開鍵を/tmp/id_rsa.pub などに用意しておき、gitユーザから読めるようにしておく。この時、公開鍵ファイルの末尾に、ユーザ名が書いてある必要がある。なければ末尾に" ユーザ名"を追加する。
gitユーザでcygwinにログイン
コマンドプロンプト> runas /user:git C:/cygwin/cygwin.bat
gitosis初期化
$ gitosis-init < /tmp/id_rsa.pub $ chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
gitosis-init実行時にエラーが出る場合:
- ImportError: No module named pkg_resources ==> setuptools-0.xxx-py2.5.egg ファイルのパーミッションを修正する(gitユーザから実行可能に)
- gitosis.init.InsecureSSHKeyUsername: Username contains not allowed characters ==> 公開鍵ファイルの末尾にユーザ名が無い(または不正な文字を含んでいる)
クライアント側の設定
PuttyGenなどで、秘密鍵・公開鍵ペアを作成する。
秘密鍵のファイル形式は、Putty形式(plink、TortoisePlink, WinSCP等で使用。拡張子ppk)の他、必要に報じてOpenSSH形式(cygwin, Linux, Mac等で使用)、ssh.com形式(Poderosa等で使用)もエクスポートしておく。形式が違うと使えないので注意
まずは動作テスト
$ ssh(またはplink.exe) -i 秘密鍵ファイル -l svnuser -P ポート番号 ホスト名 ==> "( success ( 2 2 ( ) …" みたいな応答が返ってこればOK
仮想ホスト名(セッション名)を作って、これを指定するだけで、アクセスできるようにしたい。
OpenSSH (Macとか)の設定
参考:http://www.openbsd.org/cgi-bin/man.cgi?query=ssh_config&sektion=5
~/.ssh/config を編集
# (NAT下でもセッションが切れないように) ServerAliveInterval 60 Host svn.myserver (svn用の仮想ホスト名) IdentityFile 秘密鍵 HostName 実際のホスト名 User svnuser (ポート番号を変更した場合、 Port XXX も書く) Host svn.myserver (git用の仮想ホスト名) IdentityFile 秘密鍵 HostName 実際のホスト名 User git (ポート番号を変更した場合、 Port XXX も書く)
Putty (Windows用)の設定
参考:http://www.s-m-l.org/dev/svn.html
putty.exe (puttyjp.exe)を起動し、上記のconfigと同様の設定(セッション>ホスト名、接続>データ>自動ログインユーザ名、接続>SSH>認証>プライベートキーファイル)を行い、仮想ホスト名をセッション名にして保存。
秘密鍵にパスフレーズを指定してある場合は、ここでは秘密鍵ファイルを指定せず、pageant.exeに鍵を追加して起動しておくと良い。(アクセスする度にパスフレーズを入力させられるので)
クライアントアプリケーションで、Puttyを使うように設定
- TortoiseSVNの場合: Settings > Netowrk > SSH Client > TortoisePlink.exeを指定
- msysgitの場合: インストール時に、SSHクライアントとして、 TortoisePlink.exeを指定
- Tigris.orgのsubversionの場合: %APPDATA%\Subversion\config を、以下のように編集
[tunnels] ssh = plink.exe へのパス(ディレクトリセパレータ\は/に置換。TortoisePlink.exe でもOKかも?)
結論
サーバは、素直にLinuxとかで立てた方が良いと思う。