在Windows 2003 server上安装git 服务器
首先参考了《SSH+Git Server on Windows - 在Windows下搭建Git服务器》
(http://hi.baidu.com/thinapple/blog/item/32ef0cfab2a92ed7b58f3198
or directory”。偶然看到了两篇英文的安装教程,照着做就可以了。不得不再次感叹老外做事的态度。这篇笔记欢迎转载,但请注
明原文链接(www.zxoa.com )!——by Kevin
下文除非特别说明,都是以 Administrator 用户操作。
在Windows上安装Git,要么选择msysgit,要么选择cygwin上安装。作为Git服务器,最好的选择就是cygwin。
一、安装cygwin
创建C:\cygwin和C:\cygwin\packages目录,修改cygwin目录的权限为USERS完全控制
从http://cygwin.com/setup.exe 下载安装文件放在C:\cygwin目录下,运行安装程序
开始出现安装选项,基本上就按以下选择
Choose Installation Type
Leave default Install from Internet
Choose Installation Directory
Leave default root directory C:\Cygwin
Leave default install for All Users
Leave default text file type Unix/binary
Select Local Packages Directory
Change local packages directory to C:\Cygwin\packages
Select Connection Type
Leave default direct connection
Choose Download Site(s)
Add a local mirror
Select Packages
Select Devel > git
Select Devel > git-completion
Select Devel > git-gui
Select Devel > gitk
Select Net > openssh
Select Python > python
Installation Status and Create Icons
Leave default create icon on Desktop
Leave default Add icon to Start Menu
二、设置SSH
从桌面或者开始菜单执行cygwin,第一次执行会出现如下界面
执行以下命令:
然后执行 ssh-host-config 命令,你会看到:
*** Info: Generating /etc/ssh_host_key
*** Info: Generating /etc/ssh_host_rsa_key
*** Info: Generating /etc/ssh_host_dsa_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)
输入 yes
You should see
*** Info: Note that creating a new user requires that the current account have
*** Info: Administrator privileges.
*** Query: new local account 'sshd'? (yes/no)
输入 yes
You should see
*** Info: Updating /etc/sshd_config file
*** Warning: The following functions require administrator privileges!
*** Query: Do you want to install sshd as a service?
*** Query: (Say "no" if it is already installed as a service) (yes/no)
输入yes
You should see
*** Info: Note that the CYGWIN variable must contain at least "ntsec"
*** Info: for sshd to be able to change user context without password.
*** Query: Enter the value of CYGWIN for the daemon: []
输入binmode tty ntsec
You should see
*** Info: On Windows Server 2003, Windows Vista , and above, the
*** Info: SYSTEM account cannot setuid to other users -- a capability
*** Info: sshd requires.
*** Info: account.
*** Info: You appear to be running Windows 2003 Server or later.
*** Info: and later systems, it's not possible to use the LocalSystem
*** Info: account for services that can change the user id without an
*** Info: explicit password (such as passwordless logins [e.g. public key
*** Info: authentication] via sshd).
*** Info: If you want to enable that functionality, it's required to create
*** Info: a new account with special privileges (unless a similar account
*** Info: already exists). This account is then used to run these special
*** Info: servers.
*** Info: Note that creating a new user requires that the current account
*** Info: have Administrator privileges itself.
*** Info: No privileged account could be found.
*** Info: This script plans to use 'cyg_server'.
*** Info: 'cyg_server' will only be used by registered services.
*** Query: Do you want to use a different name? (yes/no)
输入no
You should see
*** Query: Create new privileged user account 'cyg_server'? (yes/no)
输入yes
You should see
*** Info: Please enter a password for new user cyg_server.
*** Info: that this password matches the password rules given on your system.
*** Info: Entering no password will exit the configuration.
*** Query: Please enter the password:输入密码
Type and confirm a password for the new ‘cyg_server’ account.
After confirming the password, you should see
*** Info: User 'cyg_server' has been created with password 'azxggsri7#35z'.
*** Info: If you change the password, please remember also to change the
*** Info: password for the installed services which use (or will soon use)
*** Info: the 'cyg_server' account.
*** Info: Also keep in mind that the user 'cyg_server' needs read permissions
*** Info: on all users' relevant files for the services running as 'cyg_server'.
*** Info: In particular, for the sshd server all users' .ssh/authorized_keys
*** Info: files must have appropriate permissions to allow public key
*** Info: authentication. (Re-)running ssh-user-config for each user will set
*** Info: these permissions corrently. [Similary restrictions apply, for
*** Info: instance, for .rhosts files if the rshd server is running, etc].
*** Info: The sshd service has been installed under the 'cyg_server'
*** Info: account.
*** Info: `cygrunsrv -S sshd'.
*** Info: after the next reboot.
*** Info: Host configuration finished. Have fun!
chmod +r /etc/passwd
chmod u+w /etc/passwd
chmod +r /etc/group
chmod 755 /var
看到最后的”Have fun!”,SSHD安装完成。
执行 net start sshd ,启动服务。也可以到Windows的服务里,去启动”cygwin ssh”这个服务。在windows的DOS窗口下,输入
netstat –an ,查看一下TCP 22号端口有没有在监听。
三、安装Python Setuptools
首先检查一下python的版本,我这边是2.5的
Python –V
到http://pypi.python.org/pypi/setuptools 去找到相应版本的setuptools,我下载的时候是这个版本setuptools-0.6c11-
py2.5.egg,保存到C:\cygwin\home\Administrator目录下
在cygwin命令行下,执行
sh setuptools-0.6c11-py2.5.egg
你会看到:
Processing setuptools-0.6c9-py2.5.egg
Copying setuptools-0.6c9-py2.5.egg to /usr/lib/python2.5/site-packages
Adding setuptools 0.6c9 to easy-install.pth file
Installing easy_install script to /usr/bin
Installing easy_install-2.5 script to /usr/bin
Installed /usr/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg
Processing dependencies for setuptools==0.6c9
Finished processing dependencies for setuptools==0.6c9
然后执行
chmod +r /usr/lib/python2.5/ -R
四、安装gitosis
用pwd查看一下当前路径,或者直接键入cd ~ 回到home目录下,执行
git clone git://eagain.net/gitosis.git或者git clone https://github.com/res0nat0r/gitosis.git
在当前目录下会出现 gitosis 目录。
l
cd gitosis
python setup.py install
接着打开“计算机管理”——“用户管理”,添加一个名为git的用户。注意,要选上“用户不能更改密码”和“密码永不过期”选
项。
在cygwin里执行
mkpasswd -l -u git –p /home >> /etc/passwd
执行完后用 cat /etc/passwd 看看 git 用户有没有添加进去
在继续安装之前,先到你准备用来最管理客户端用的PC或者笔记本前,生成一个SSH key。你的PC或者笔记本的名称最好是英文字母
与数字,不能有下划线等其它特殊字符,更不要用中文。如果你已经安装了msysgit,那么很简单,从开始菜单打开git bash,在命
令行下输入ssh-keygen,然后一直回车即可,就会在C:\Documents and Settings\你的登录用户名\.ssh下生成id.rsa和id_rsa.pub
这两个文件。将其中的id_rsa.pub文件拷贝到服务器的C:\cygwin\tmp下。(如何生成ssh key,可以参考
http://help.github.com/msysgit-key-setup/ )ssh-keygen -t rsa -C "your_email@example.com"
在服务器上,打开一个DOS窗口,执行
runas /user:git C:/cygwin/cygwin.bat
l
gitosis-init < /tmp/id_rsa.pub
我们会看到如下输出:
Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/
然后我们可以输入 exit 退出。
回到用Administrator登录的cygwin窗口,执行
chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
gitosis就顺利的安装完成了。
五、
回到我们管理客户端(PC或者笔记本)前,打开 git bash,进入到我们用来保存项目的目录下,假设是d:\repos,执行
git clone git@your-server:gitosis-admin.git
选择接受 key ,并且如果要求输入密码时,输入服务器上 git 用户的密码。如果出现“ fetal :‘ gitosis-admin ’ does not
appear to be a git repository ”的错误,可以试着用
git clone git@your-server:repositories/gitosis-admin.git
命令执行完后,在 d:\repos下生成了gitosis-admin目录,这个目录下有一个keydir目录和gitosis.conf文件。修改gitosis.conf文
件
[group gitosis-admin]
writable = gitosis-admin
members = me@myhost
根据你自己的情况,加入
[group team1]
members = john@rnd01 bob
@rnd02 sarah@rnd03
writable = project1 project2
[group team2]
members = bob@rnd02 tina
@rnd04 tom@rnd05
writable = project3 project4
注意:“@”前面是登录的用户名,后面是机器名。一般情况下,都是使用administrator登录,那么用户名都是administrator,机
器名就照实写。
然后把每个用户生成的ssh key pub都保存到keydir目录下。名字必须与配置文件里一致。如上例配置,则john@rnd01.pub 该E-
mail地址已受到防止垃圾邮件机器人的保护,您必须启用浏览器的Java Script才能看到。 bob@rnd02.pub 该E-mail地址已受到防止
垃圾邮件机器人的保护,您必须启用浏览器的Java Script才能看到。 sarah@rnd03.pub 该E-mail地址已受到防止垃圾邮件机器人的
保护,您必须启用浏览器的Java Script才能看到。 tina@rnd04.pub 该E-mail地址已受到防止垃圾邮件机器人的保护,您必须启用
浏览器的Java Script才能看到。 tom@rnd05.pub 该E-mail地址已受到防止垃圾邮件机器人的保护,您必须启用浏览器的Java
Script才能看到。
接下来在管理客户端上执行
git commit -a -m "setup users and access"
fatal: Not a git repository (or any of the parent directories): .git
git init
git push
到服务器的相应目录下,检查是否push成功。
添加新项目(以porject1为例)
john@rnd01 bob @rnd02 sarah@rnd03 任何一个人,登录后在工作目录下如 d:\repos,打开git bash,执行
mkdir project1
cd project1
git init
touch .gitignore
git
commit -a -m "Init project1"git remote add origin git@your-server:repositories/project1.git
git push origin master:refs/heads/master
项目添加成功,组成员可以正常使用了。
参考文章:
http://www.shannoncornish.com/blog/category/uncategorized/
http://www.markembling.info/view/git-server-gitosis-and-cygwin-on-windows
(下载PDF文件 )
上面用的是命令式的客户端,感觉不太适用可以用下面二种客户端,第一种安装后也是可以使用的,第二种更方便一点,更适合在
windows下的操作习惯。
一 安装
(1)下载Git支持环境----Git-1.7.3.1-preview20101002.exe并安装:http://msysgit.googlecode.com/files/Git-1.7.3.1 -
preview20101002.exe
下载后一路默认安装,安装好后点击UIT GUI进入管理界面,先点击帮助生成key后,传入服务器上,然后输入远程服务器地址和本地
存放的地址就可以下载服务器上的文件了,其它操作也很简单,大概学一下就会了,
(2)下载Git客户端----TortoiseGit-1.5.8.0-64bit.msi并安装:http://tortoisegit.googlecode.com/files/TortoiseGit -
1.5.8.0-64bit.msi ,我的机器是64位的,所以下了个64位的安装包,请根据情况选择适合自己的安装包
二 使用
下面以利用安装好的TortoiseGit下载HQ源码为例来讲述一下TortoiseGit的使用
在D盘建立文件夹HQSourceCode,然后在文件夹上右击,选择“Git Clone....”:
点击“ok”,这样就可以将HQ的源码下载下来了。
另外的方法可参考
http://blog.sina.com.cn/s/blog_67c1651501012z7z.html
http://blog.163.com/user_zhaopeng/blog/static/166022708201211304312806/