Windows上使用Cygwin搭建gitolite服务器

我的环境

Windows XP SP3 + cygwin(1.7.18-1)+ gitolite

 

参考文献:

http://therightstuff.de/CommentView,guid,b969ea4d-8d2c-42af-9806-de3631f4df68.aspx

http://alone11.iteye.com/blog/1078297

安装cygwin

官网:http://www.cygwin.com/

cygwin是一个在windows平台上运行的unix模拟环境。官网上有详细的安装说明。

安装Cygwin

 

1.下载 setup.exe

2.打开setup.exe, 选择Install from Internet

3.选择安装Cygwin到C:\cygwin

4.选择存储下载文件的目录为C:\

5.选择下载站点的镜像

6.选择安装以下软件包:

◦Net | openssh (不要选成openssl)

◦Devel | git

◦Devel |git-completion

◦Devel | git-gui

◦Devel | gitk

◦Editors | vim

集成Cygwin和Windows Security

In preparation for the SSH serverinstallation in the next section, we need to provide Cygwin with means toimpersonate a SSH user as a Windows user with public key authentication. Youcan read more aboutintegrating with Windows Security in the Cygwin documentation.

 

1.      打开C:\cygwin\Cygwin.bat

2.      执行 bin/cyglsa-config

Warning: Registering the Cygwin LSA authentication package requires

administrator privileges!  You also have to reboot the machine to

activate the change.

 

Are you sure you want to continue? (yes/no)

3.      选择yes

4.      重启Windows

搭建SSH服务器

1.      打开C:\cygwin\Cygwin.bat

2.      执行 ssh-host-config,如果提示命令找不到,那估计是你安装cygwin时没有安装openssh

$ ssh-host-config

 

*** Info: Generating /etc/ssh_host_key

*** Info: Generating /etc/ssh_host_rsa_key

*** Info: Generating /etc/ssh_host_dsa_key

*** Info: Generating /etc/ssh_host_ecdsa_key

*** Info: Creating default /etc/ssh_config file

*** Info: Creating default /etc/sshd_config file

*** Info: Privilege separation is set to yes by default since OpenSSH 3.3.

*** Info: However, this requires a non-privileged account called 'sshd'.

*** Info: For more info on privilege separation read /usr/share/doc/openssh/README.privsep.

*** Query: Should privilege separation be used? (yes/no)

3.      输入yes

*** Info: Updating /etc/sshd_config file

 

*** Query: Do you want to install sshd as a service?

*** Query: (Say "no" if it is already installed as a service) (yes/no)

4.      输入yes

*** Query: Enter the value of CYGWIN for the daemon: []

5.      直接回车

*** Info: The sshd service has been installed under the LocalSystem

*** Info: account (also known as SYSTEM). To start the service now, call

*** Info: `net start sshd' or `cygrunsrv -S sshd'.  Otherwise, it

*** Info: will start automatically after the next reboot.

 

*** Info: Host configuration finished. Have fun!

 

自此SSH服务已经搭建完毕,通过cygrunsrv –L命令查看sshd服务已经运行。

Administrator@WWW-8B0A55396B4 ~

$  cygrunsrv -L

sshd

 

允许SSH客户端访问

       创建一个名为git的用户,后续就是通过这个用户来访问版本库的。

1.      在windows控制面板中创建一个名为git的用户,设置密码,并确保密码不会过期。

2.      在Cygwin Bash中,执行命令: mkpasswd -l -u git >> /etc/passwd

口令认证登陆SSH服务器

通过口令认证登陆SSH服务器来验证下SSH服务器正常。

1.      打开Cygwin Bash

2.      $ ssh git@127.0.0.1,输入windows用户git创建时指定的密码

Administrator@WWW-8B0A55396B4 ~

$ ssh git@127.0.0.1

git@127.0.0.1's password:

Could not chdir to home directory /home/git: No such file or directory

Copying skeleton files.

These files are for the users to personalise their cygwin experience.

 

They will never be overwritten nor automatically updated.

 

`./.bashrc' -> `/home/git//.bashrc'

`./.bash_profile' -> `/home/git//.bash_profile'

`./.inputrc' -> `/home/git//.inputrc'

`./.profile' -> `/home/git//.profile'

 

git@WWW-8B0A55396B4 ~

$

3.      以git用户登录成功

4.      退出登陆

git@WWW-8B0A55396B4 ~

$ exit

logout

Connection to 127.0.0.1 closed.

 

密钥认证登陆SSH服务器

1.      打开Cygwin Bash

2.      生成密钥对文件

Administrator@WWW-8B0A55396B4 ~

$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/Administrator/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/Administrator/.ssh/id_rsa.

Your public key has been saved in /home/Administrator/.ssh/id_rsa.pub.

The key fingerprint is:

4f:4f:ba:e6:60:b6:af:9c:6e:17:cc:47:b3:32:96:2f Administrator@WWW-8B0A55396B4

The key's randomart image is:

+--[ RSA 2048]----+

|                 |

|                 |

|                 |

|            o    |

|        So.o.o   |

|         oO+o    |

|        +.o*.    |

|       +.+E..    |

|       o**+.     |

+-----------------+

 

3.      ssh-copy-id git@127.0.0.1 (输入git用户密码)

将生成的id_rsa.pub文件内容附加到服务器对应帐号git下的authorized_keys文件末尾。

Administrator@WWW-8B0A55396B4 ~

$ ssh-copy-id git@127.0.0.1

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

git@127.0.0.1's password:

 

Number of key(s) added: 1

 

Now try logging into the machine, with:   "ssh 'git@127.0.0.1'"

and check to make sure that only the key(s) you wanted were added.

 

4.      密钥认证登陆,不用输入密码即可登录成功

Administrator@WWW-8B0A55396B4 ~

$ ssh git@127.0.0.1

Last login: Sat May  4 17:04:19 2013 from localhost

 

git@WWW-8B0A55396B4 ~

$

安装Gitolite

官网:https://github.com/sitaramc/gitolite

1.      打开Cygwin Bash

2.      登陆git用户:ssh git@127.0.0.1,我将gitolite安装在git用户环境中。

3.      git clonegit://github.com/sitaramc/gitolite.git。

 

再继续之前,先做些说明,安装步骤可以参考gitolite\ README.txt文件。安装gitolite之前,你需要在客户端先准备好gitolite管理员的SSH公钥文件(如我的文件是叫admin.pub),并将admin.pub文件放在/home/git目录下,安装过程中要用到。

 

4.      mkdir -p $HOME/bin

5.      gitolite/install -to $HOME/bin

6.      $HOME/bin/gitolite setup -pkadmin.pub

git@WWW-8B0A55396B4 ~

$ $HOME/bin/gitolite setup -pk admin.pub

Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/

Initialized empty Git repository in /home/git/repositories/testing.git/

 

 

7.      用管理员的密钥登陆下服务器,发现如下错误。

Administrator@WWW-8B0A55396B4 ~

$ ssh git@127.0.0.1 -i ~/.ssh/admin

PTY allocation request failed on channel 0

 running gitolite3 v3.5.1-2-g962e465 on git 1.7.9

 

FIND: ▒▒▒▒▒▒ʽ▒▒▒▒ȷ

Connection to 127.0.0.1 closed.

该错误是因为cygwin sshd服务的环境变量引起的。通过以下命令重新安装sshd服务,并指定环境变量。

Administrator@WWW-8B0A55396B4 ~

$ cygrunsrv --remove sshd

 

Administrator@WWW-8B0A55396B4 ~

$ cygrunsrv -I sshd -d "CYGWIN sshd" -p /usr/sbin/sshd --env "PATH=/usr/local/bin:/usr/bin:/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem"

 

8.      再用管理员的密钥登陆就正常了

Administrator@WWW-8B0A55396B4 ~

$ ssh git@127.0.0.1 -i ~/.ssh/admin

PTY allocation request failed on channel 0

hello admin, this is git@WWW-8B0A55396B4 running gitolite3 v3.5.1-2-g962e465 on git 1.7.9

 

 R W    gitolite-admin

 R W    testing

Connection to 127.0.0.1 closed.

 

 

9.      设置主机别名

host gitolite

  user git

  hostname 127.0.0.1

  port 22

  identityfile ~/.ssh/admin

10.  管理员克隆gitolite-admin

Administrator@WWW-8B0A55396B4 ~

$ git clone gitolite:gitolite-admin

Cloning into 'gitolite-admin'...

remote: Counting objects: 6, done.

remote: Compressing objects: 100% (4/4), done.

remote: Total 6 (delta 0), reused 0 (delta 0)

Receiving objects: 100% (6/6), done.

 

Administrator@WWW-8B0A55396B4 ~

 

至于gitolite如何使用,在此不介绍。

cygwin卸载

cygwin做的这么好,让我想不通的是怎么不能一键卸载。一开始根本就是无从下手,在cygwin安装的文件夹下和windows的添加和删除程序中根本就没有它的存在,如果是直接shift+delete这个文件夹,有时系统还会报告出错误,说某些文件无法删除。

在官网http://cygwin.com/faq.html的“How do Iuninstall all of Cygwin?”章节中有详细的卸载介绍(http://cygwin.com/faq-nochunks.html#faq.setup.uninstall-all)。大体思路是这样:

 

◆检查是否有Cygwin services在运行,有就先删除这些服务(可参考http://cygwin.com/faq/faq.setup.html#faq.setup.uninstall-service)。如下图命令所示:

Administrator@WWW-8B0A55396B4 ~

$ cygrunsrv -L

sshd

 

Administrator@WWW-8B0A55396B4 ~

$ cygrunsrv --stop sshd

 

Administrator@WWW-8B0A55396B4 ~

$ cygrunsrv --remove sshd

 

Administrator@WWW-8B0A55396B4 ~

$ cygrunsrv -L

 

Administrator@WWW-8B0A55396B4 ~

$

 

◆删除cygwin整个目录,如果有提示无法删除的,进入安全模式删除。

 

◆删除桌面上的icon,和开始菜单里的启动文件夹

 

◆删除注册表里的相关项

HKEY_LOCAL_MACHINE/SOFTWARE/CygnusSolutions

HKEY_CURRENT_USER/Software/Cygnus Solutions

 

◆删除环境变量(PATH,CYGWIN)

环境变量PATH里的c:/cygwin/bin; 还有名叫CYGWIN的变量

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值