Windows上使用Cygwin和Gitolite搭建Git服务器

安装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 | git-svn (如果需要同时提交到svn)
    • Devel | gitk
    • Editors | vim

集成Cygwin和Windows Security

  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
    *** 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:Creatingdefault/etc/ssh_configfile

    ***Info:Creatingdefault/etc/sshd_configfile

    ***Info:PrivilegeseparationissettoyesbydefaultsinceOpenSSH3.3.

    ***Info:However,thisrequiresanon-privilegedaccountcalled'sshd'.

    ***Info:Formoreinfoonprivilegeseparationread/usr/share/doc/openssh/README.privsep.

    *** Query: Should privilege separation be used? (yes/no)
  3. 选择yes
    *** Info: Note that creating a new user requires that the current account have

    ***Info:Administratorprivileges.Shouldthisscriptattempttocreatea

    *** Query: new local account 'sshd'? (yes/no)
  4. 选择yes
    *** Info: Updating /etc/sshd_config file

    ***Info:AddedsshtoC:\WINDOWS\system32\driversc\services

    ***Warning:Thefollowingfunctionsrequireadministratorprivileges!

    ***Query:Doyouwanttoinstallsshdasaservice?

    *** Query: (Say "no" if it is already installed as a service) (yes/no)
  5. 选择yes
    *** Query: Enter the value of CYGWIN for the daemon: []
  6. 输入tty
    *** Info: The sshd service has been installed under the LocalSystem

    ***Info:account(alsoknownasSYSTEM).Tostarttheservicenow,call

    ***Info:`netstartsshd'or`cygrunsrv-Ssshd'.Otherwise,it

    ***Info:willstartautomaticallyafterthenextreboot.

    *** Info: Host configuration finished. Have fun!
  7. 配置结束,确认端口22可用。启动服务:sc start sshd

允许SSH客户端访问

  1. 创建一个名为git的用户,设置密码,并确保密码不会过期。
  2. 在Cygwin Bash中,执行命令: mkpasswd -l -u git >> /etc/passwd

验证下SSH登录

  1. 打开Cygwin Bash
  2. $ ssh git@10.0.2.15
    Administrator@china-fe1bdcde5 ~

    $sshgit@10.0.2.15

    Theauthenticityofhost'10.0.2.15(10.0.2.15)'can'tbeestablished.

    ECDSAkeyfingerprintis5d:a6:81:98:43:fa:5a:f6:df:ba:18:b9:a0:76:87:f8.

    Areyousureyouwanttocontinueconnecting(yes/no)?yes

    Warning:Permanentlyadded'10.0.2.15'(ECDSA)tothelistofknownhosts.

    git@10.0.2.15'spassword:

    Couldnotchdirtohomedirectory/home/git:Nosuchfileordirectory

    Copyingskeletonfiles.

    Thesefilesarefortheuserstopersonalisetheircygwinexperience.

    Theywillneverbeoverwrittennorautomaticallyupdated.

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

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

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

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

    git@china-fe1bdcde5~

    $
  3. 以git用户登录成功

创建SSH密钥, 并使能够通过SSH identity以git用户登录SSH服务器

  1. 打开Cygwin Bash
  2. $ ssh-keygen -t rsa (所有输入都为空,即使用默认配置,密码为空)
    $ ssh-keygen -t rsa

    Generatingpublic/privatersakeypair.

    Enterfileinwhichtosavethekey(/home/Administrator/.ssh/id_rsa):

    Enterpassphrase(emptyfornopassphrase):

    Entersamepassphraseagain:

    Youridentificationhasbeensavedin/home/Administrator/.ssh/id_rsa.

    Yourpublickeyhasbeensavedin/home/Administrator/.ssh/id_rsa.pub.

    Thekeyfingerprintis:

    6a:02:9f:42:99:7c:fe:52:e7:a9:fe:1b:15:1e:70:31Administrator@china-fe1bdcde5

    Thekey'srandomartimageis:

    +--[RSA2048]----+

    |.E.|

    |o.|

    |o|

    |.o.o|

    |*.So|

    |.=.....|

    |.=.oo..|

    |..+o.|

    |o+oo.|

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

    git@10.0.2.15'spassword:

    Nowtryloggingintothemachine,with"ssh'git@10.0.2.15'",andcheckin:

    ~/.ssh/authorized_keys

    to make sure we haven't added extra keys that you weren't expecting.
  4. 验证下,以git用户登录:ssh git@10.0.2.15
    $ ssh git@10.0.2.15

    Lastlogin:SatJun1123:06:142011fromchina-fe1bdcde5

    git@china-fe1bdcde5~

    $
  5. 不需要输入密码,即登录成功

安装Gitolite

  1. 打开Cygwin Bash
  2. $ cd /tmp
  3. $ git clone git://github.com/sitaramc/gitolite.git
  4. $ cd gitolite/src/
  5. $ ./gl-easy-install git 10.0.2.15 alec (可以单独执行gl-easy-install查看各个参数的意义)
  6. 根据安装向导一步步完成配置(其中需要配置alec的密码,生成SSH密钥)
  7. 当走到需要编辑配置文件(用vim编辑)的时候,在开头插入:$ENV{PATH} = "/usr/local/bin:/bin:/usr/bin";,保存并退出(:wq) 如: 
    # configuration variables for gitolite

    $ENV{PATH}="/usr/local/bin:/bin:/usr/bin";

    #PLEASEREADTHEDOCUMENTATIONBEFOREEDITINGORASKINGQUESTIONS

    #(http://github.com/sitaramc/gitolite/blob/pu/doc/gitolite.rc.mkd)

    #(orhttp://sitaramc.github.com/gitolite/doc/gitolite.rc.html)

    #thisfileisinperlsyntax.However,youdoNOTneedtoknowperltoedit

    # it; it should be fairly self-explanatory and easy to maintain
  8. 继续完成安装。当完成安装之后,可以在当前用户的home目录下面看到gitolite-admin目录。
  9. $ cd ~/gitolite-admin
  10. $ git status
    Administrator@china-fe1bdcde5 ~/gitolite-admin

    $gitstatus

    #Onbranchmaster

    nothing to commit (working directory clean)

到此整个git server已经安装结束,可以参考Gitolite文档来配置:添加user和repository

相关推荐