sshd cygwin 再インストール まとめ

Windows 7 (64)で sshd を動かすためには。

  • cygwin のインストール

http://www.kkaneko.com/rinkou/cygwin/cygwin.html を参考に「CYGWIN バージョンのインストール」の1〜15を行う。
そのときに openssh と cygrunsrv も入れること。
(後で apt-cyg install openssh とかやってもいいけど)

  • cygwin terminal を管理者権限で実行し下記コマンドを実行。

$ ssh-host-config (-y オプションは付けない)
Query: Overwrite existing /etc/ssh_config file? (yes/no) yes
Query: Overwrite existing /etc/sshd_config file? (yes/no) yes
Query: Should privilege separation be used? (yes/no) yes
Query: Do you want to install sshd as a service?
Query: (Say "no" if it is already installed as a service) (yes/no) yes
Query: Enter the value of CYGWIN for the daemon: []
Query: Do you want to use a different name? (yes/no) yes
Query: Enter the new user name: cygwin
Query: Reenter: cygwin
Query: Create new privileged user account 'cygwin'? (yes/no) yes
Query: Please enter the password: xxxxxx
Query: Reenter: xxxxxx

長いのでQuery以外は省略してます。

ここでは Windows 特権ユーザ(privilege server)を作り、Unixユーザアカウント名に cygwin passwd は xxxxxx を用いています。


cygwin:xxxx:xx:xx:Privileged server,xxx\cygwin,xxx:/var/empty:/bin/false

cygwin:xxxx:xx:xx:Privileged server,xxx\cygwin,xxx:/home/cygwin:/bin/bash
として、Windows で c:\cygwin\home に cygwin, cygwin\Git というフォルダを作ります。

  • RSA公開鍵認証をさせるために sshd の設定を行う

cygwin terminal で /etc/sshd_config を下記のように変更


#PermitRootLogin yes
#StrictModes no
:
#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeyFile .ssh/authorized_keys

PermitRootLogin no
StrictModes yes
:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeyFile .ssh/authorized_keys
さらに公開鍵認証に限定させるためには、http://gentoo.reichsarchiv.jp/item/17 を参考に、

#RhostsRSAAuthentication no
#PasswordAuthentication yes
#PermitEmptyPasswords no
#ChallengeResponseAuthentication yes

RhostsRSAAuthentication no
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
とする。(未確認)

  • Windows のコントロールパネルから(?よくわからないけど、services で表示される「管理ツール→ローカル サービスの表示」)、CYGWIN sshd を起動させる。
  • cygwin terminal(先ほどの管理者権限のterminal)で下記を実行


$ cd /home/cygwin/Git; touch git-daemon-export-all-ok (最初に一回だけ必要)
$ git daemon --export-all --enable=receive-pack --base-path=/home/cygwin/Git/

  • RSAキーの作成(本当はコピーしちゃいけないとかだけど)

一般ユーザでの cygwin terminal で RSAキーを作成
$ ssh-keygen.exe -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kageyu/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/kageyu/.ssh/id_rsa.
Your public key has been saved in /home/kageyu/.ssh/id_rsa.pub.特権ユーザ cygwin terminal で


$ mkdir /home/cygwin/.ssh
$ chmod 700 /home/cygwin/.ssh
/home/kageyu/.ssh/id_rsa.pub を /home/cygwin/.ssh/authorized_keys にコピー

$ chmod 600 /home/cygwin/.ssh/authorized_keys
$ chown -R cygwin /home/cygwin/.ssh/
あとは、cygwin の /home/kageyu/.ssh/id_rsa, id_rsa.pub を Windows ユーザの c:\Users\kageyu\.ssh\ にコピーして出来上がり。





ssh://cygwin@xx.xx.xx.xx/home/cygwin/Git/Documents/Bank.git/