Updated on 2012-03-06 to reflect the changes to the Gitolite installation process.
For obvious reasons, a couple weeks ago my team made the switch to Git. Hosting a Git server on Windows is by all means possible, and there are two options:
A notable aspect of both solutions is that repository configuration and permissions management is done through Git itself. Over time, you will build a versioned history of the server configuration. Without further ado, let’s get started!
You’ll see that we have to deal with Cygwin and SSH mostly. Gitolite’s installation is pretty easy and does not require a lot of work by itself. Getting the Windows Server in a condition where it handles SSH takes most of our time.
I recommend leaving the setup.exe in place, as you can use the installer to add, remove or upgrade Cygwin packages later.
Repeat the process on your local machine, this time with an extended set of packages to install:
In preparation for the SSH server installation in the next section, we need to provide Cygwin with means to impersonate a SSH user as a Windows user with public key authentication. You can read more about integrating with Windows Security in the Cygwin documentation.
Copying skeleton files. These files are for the user to personalise their cygwin experience. They will never be overwritten nor automatically updated. `./.bashrc' -> `/home/Administrator//.bashrc' `./.bash_profile' -> `/home/Administrator//.bash_profile' `./.inputrc' -> `/home/Administrator//.inputrc' Administrator@GIT-SERVER ~ $
/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)
yes
Cygwin LSA authentication package registered. Activating Cygwin's LSA authentication package requires to reboot.
SSH will encrypt and authenticate connections to your Git repositories. SSH will use public key authentication to check if the user is permitted to access the server. Once the user got past the SSH security check Gitolite will take over handling the request.
When the Git server finished rebooting:
ssh-host-config
Administrator@GIT-SERVER ~ $ 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)
*** Info: Note that creating a new user requires that the current account have *** Info: Administrator privileges. Should this script attempt to create a *** Query: new local account 'sshd'? (yes/no)
*** 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)
*** Query: Enter the value of CYGWIN for the daemon: []
*** Info: On Windows Server 2003, Windows Vista, and above, the *** Info: SYSTEM account cannot setuid to other users -- a capability *** Info: sshd requires. You need to have or to create a privileged *** Info: account. This script will help you do so. *** Info: You appear to be running Windows 2003 Server or later. On 2003 *** 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
*** Query: Create new privileged user account 'cyg_server'? (yes/no)
*** Info: Please enter a password for new user cyg_server. Please be sure *** 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:
netsh advfirewall firewall add rule dir=in action=allow localport=22 protocol=tcp name="Cygwin SSHD"
sc start sshd
Next we will enable SSH access for the git user that will be used to access repositories.
mkpasswd -l -u git >> /etc/passwd
ssh git@git-server
you@YOUR-MACHINE ~ $ ssh git@git-server The authenticity of host 'git-server (172.16.0.42)' can't be established. RSA key fingerprint is 13:16:ba:00:d3:ac:d6:f2:bf:36:f4:28:df:fc:d5:26. Are you sure you want to continue connecting (yes/no)?
Warning: Permanently added 'git-server,172.16.0.42' (RSA) to the list of known hosts. git@git-server's password:
Copying skeleton files. These files are for the user 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' git@git-server ~ $
logout
The next steps to create two SSH identities. The first is required to access the soon-to-be Git server, the second will be used to install and update Gitolite. Execute the following commands on your local machine.
ssh-user-config
*** Query: Shall I create an SSH1 RSA identity file for you? (yes/no)
*** Query: Shall I create an SSH2 RSA identity file for you? (yes/no)
*** Info: Generating /home/agross/.ssh/id_rsa Enter passphrase (empty for no passphrase):
*** Query: Do you want to use this identity to login to this machine? (yes/no)
*** Query: Shall I create an SSH2 DSA identity file for you? (yes/no)
*** Info: Configuration finished. Have fun!
ssh-keygen -f ~/.ssh/gitolite-admin
In order to be able to log-in to the Git server as the git user using your gitolite-admin SSH identity, execute ssh-copy-id -i ~/.ssh/gitolite-admin git@git-server. This adds the gitolite-admin public key to the list of authorized keys for the git account.
gitolite-admin
ssh-copy-id -i ~/.ssh/gitolite-admin git@git-server
you@YOUR-MACHINE ~ $ ssh-copy-id -i ~/.ssh/gitolite-admin git@git-server git@git-server's password: Now try logging into the machine, with "ssh 'git@git-server'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
Verifying that public key authentication works, on the next log-in you do not have to enter git@git-server’s password.
you@YOUR-MACHINE ~ $ ssh -i ~/.ssh/gitolite-admin git@gitserver Last login: Fri Mar 26 02:04:40 2010 from your-machine git@git-server ~ $
You are now ready to install Gitolite!
The Gitolite installation process documentation is sufficient to get you started. There's just one more thing that you need to do on Windows.
Upgrades to newer versions of Gitolite are easy and run like the first-time installation. That is, you can just repeat the process outlined below, probably with a new Gitolite version. This installation method requires a SSH login, but we’ve just set-up things this way.
$ scp -i ~/.ssh/gitolite-admin ~/.ssh/id_rsa.pub git@gitserver:your-name.pub
ssh -i ~/.ssh/gitolite-admin git@gitserver
.bashrc
vim .bashrc
PATH=/home/git/bin:$PATH
:wq
:q!
source .bashrc
PATH
git@gitserver ~ $ git clone git://github.com/sitaramc/gitolite Cloning into 'gitolite'... remote: Counting objects: 5360, done. remote: Compressing objects: 100% (1806/1806), done. remote: Total 5360 (delta 3708), reused 5118 (delta 3498) Receiving objects: 100% (5360/5360), 1.79 MiB | 655 KiB/s, done. Resolving deltas: 100% (3708/3708), done. git@gitserver ~ $ gitolite/src/gl-system-install using default values for EUID=1005: /home/git/bin, /home/git/share/gitolite/conf, /home/git/share/gitolite/hooks git@gitserver ~ $ gl-setup -q ~/your-name.pub creating gitolite-admin... Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/ creating testing... Initialized empty Git repository in /home/git/repositories/testing.git/ [master (root-commit) 3725b39] gl-setup -q /home/git/your-name.pub 2 files changed, 8 insertions(+), 0 deletions(-) create mode 100644 conf/gitolite.conf create mode 100644 keydir/your-name.pub
gl-setup
.gitolite.rc
vim .gitolite.rc
$ENV{PATH} = "/usr/local/bin:/bin:/usr/bin";
:w
Once the installation is finished, you can clone the gitolite-admin repository to your desktop.
$ git clone git@gitserver:gitolite-admin.git
To add repositories or change permissions on existing repositories, please refer to the Gitolite documentation. The process uses Git itself, which is awesome:
If you ever want to update or manage the Gitolite server, you can still SSH into the server with
$ ssh -i ~/.ssh/gitolite-admin git@gitserver
This guide as been pretty long, longer than I wish it had been. Following Shannon Cornish’s example, I wanted it to be rather too verbose than too short. At least, I did appreciate the detail of Shannon’s instructions when I installed Gitosis back in December. I’ve just begun to grasp the power of Unix – leveraging a set of tiny programs to orchestrate a system.
With the setup you have now in place, you can do anything you like – it’s a complete Git server. However, if you want to publish your server on the internet there’s more you will want to take care of. I will go into that in a future post, detailing some of Cygwin’s security features that helped us reduce the number of attacks on our server. Also, I will take a look at how you can enable the Gitweb Repository Browser using the lighttpd web server.
a@href@title, blockquote@cite, em, strike, strong, sub, sup, u