Set up a git server on Windows

Source: Internet
Author: User
Tags git client openssh server ssh server using git version control system
Tortoisegit + msysgit + copssh + Windows XP as server

1. Required Software
Msysgit ( Server And client)
Copssh (server)
Tortoisegit (client)
Junction link magic (server, optional)
The version will not be written. Find the latest version.

2. on the server
Install msysgit
Select plink instead of OpenSSH
Add git to path (second option)

Install copssh
Use default Set Install
Copssh is installed in c: \ Program Files \ ICW \ by default \

Modify copssh settings
In C: \ Program Files \ ICW \ etc \ sshd_config, uncomment the following line and set it to "no"
Passwordauthentication No

Create a Windows Account
Control Panel> User Accounts> Create new account

Activate this account in copssh
Start> Programs> copssh> "activate a user"
Select an account and use the default values (/bin/bash, and so on)
Enter the password, which must be remembered and used to activate the private key.

In C: \ Program Files \ ICW \ home, each account has a subdirectory. Send <user>. Key and <user>. Key. Pub and the password you just entered User .

Install an empty git Repository
If you want to use D: \ project1 as the GIT repository
Enter the following command in cmd:
D:
CD \ project1
Md. Git
CD. Git
Git -- bare init
In this way, D:/project1 becomes a git repository.

Grant user modification permission
Right-click on D: \ project1> Security, and allow the newly created Windows Account to "write" and "modify"

Open Port 22 on the server

Because the SSH server cannot find the GIT command, the following operations are required:
Start> copssh> Start a Unix bash shell.
CD/bin
Establish a symbolic chain to git.exe, git-receive-pack.exe, git-upload-archive.exe, git-upload-pack.exe:
$ Ln-S/cygdrive/C/program \ files/git/bin/git.exe
$ Ln-S/cygdrive/C/program \ files/git/libexec/Git-core/git-receive-pack.exe
$ Ln-S/cygdrive/C/program \ files/git/libexec/Git-core/git-upload-archive.exe

$ Ln-S/cygdrive/C/program \ files/git/libexec/Git-core/git-upload-pack.exe
(Change the path according to your own git installation path, and convert the space "\")

Optional steps: Install junction link magic
Create an empty directory named pro1 in the directory of C: \ Program Files \ ICW \ home \ User
Start junction link magic and change the GIT repository Directory D: \ project1 Junction to c: \ Program Files \ ICW \ home \ User \ pro1

End of server settings


3. On the client
For users
Private Key File For example, <user>. Key
Password of the private key file
Server address
User ID on the server


Install msysgit
Select plink
Select to put git in Windows path

Install tortoisegit
After installation, go to Settings> network> SSH settings:
SSH client = c: \ Program Files \ tortoisegit \ bin \ tortoiseplink.exe

(The following operations may fail. You need to configure the key in another way)
Run C: \ Program Files \ tortoisegit \ bin \ puttygen.exe:
The key generated in copssh is OpenSSH keys, but putty keys is required here. Convert the private key to putty.
Press "LOAD"> select file <user>. Key
Find a place to save the private key <user>. PPK
Run c: \ Program Files \ tortoisegit \ bin \ pageant.exe
Add the newly generated <user>. PPK and enter the password when querying the password
Note: after each startup, run pageant.exe, add <user>. PPK, and enter the password.

On my machine, puttygen of tortoisegit does not recognize OpenSSH keys generated by copssh. Download Latest puttygen
Http://tartarus.org /~ Simon/Putty-snapshots/x86/puttygen.exe to generate the PPK private key.
Alternatively, you can use puttygen to generate a private key in PPK format and replace the Public Key displayed in the upper part with the content in authorized_kyes of OpenSSH.
However, this will make it impossible to log on to the OpenSSH server interactively, but you can continue the following operations.

4. Start Using
Clone git repository on your machine
Url = <user >@< Server>: D:/project1
Or the path after junction is used.
Url = <user >@< Server>: pro1
If pageant.exe is not used, set "load putty key" (yes) = (path to <user>. PPK). You must enter a password for each operation on the server.
Note: When you connect to the server for the first time, you must save the public key of the server and select YES.

(The GIT client reports that a DLL on the server is not found. Copy the DLL file under the GIT installation directory to the bin of copssh)

If the GIT repository and copssh on the server are installed on the same drive letter, the drive letter can be omitted, as shown in
Url = SSH: // <user >@< Server>/project1



Git is a version control system designed for Linux kernel development. Therefore, it is closely integrated with Linux. This makes it very convenient to use in Linux. But it is not so friendly to those who are used to Windows. Although there are also projects such as msys-Git and tortorsegit, it is more and more convenient to use git on Windows. However, it is inconvenient to share your version library with other people.

In Linux, the clone remote machine version Library only needs:

Git clone user@remote.server.address: path/to/repo local_dir

It can be easily done. Can I Configure SSH on Windows and use git in the same way as Linux?

Yes. First, you need to install two tools:
1-Git: git in Windows is better than msys-git.
2-ssh: You can use copssh to start the SSH service on windows, not just the client.

There is no difficulty in installing these two tools. It is assumed that git is installed in the C: \ git directory, and copssh is installed in the C: \ ICW directory. After installation, git can obtain the version library remotely, and a user can log on to ssh. Assume that this user is git (by default, no user can log on to copssh, and a Windows user with a password needs to be manually activated ).

In this case, you can execute basic commands such as LS and CD after logging on from other machines using git users through SSH. However, git cannot run. Therefore, you cannot use SSH to release the GIT repository. To achieve this, you need to make some settings.

First, you need to find the CMD directory in the GIT installation directory, which is c: \ git \ cmd. Create the following files: git, Git-upload-pack, Git-upload-archive, and git-receive-pack. There is no extension here. It is mainly executed by bash after logon. Each file has only one row, which is:
Git. CMD $ *
Git upload-pack $ *
Git upload-archive write git upload-archive $ *
Git-receive-pack write git receive-pack $ *

Then, you need to add a path to the logged-on user to ensure that the command added above can be found and executed. Find the profile file under etc in the installation directory of copssh. Here is c: \ ICW \ etc \ profile: Add two lines at the end of the file

Gitpath = '/bin/cygpath C:/git/cmd' # here is not a quotation mark. The path is cmd under git. The slash should also be UNIX.
Export Path = "$ path: $ gitpath"

Then, use the GIT user to log on again from SSH. You can use the GIT command.
For example, create a test database:
Mkdir testgit
CD testgit
Git init
Touch a B c
Git add.
Git commit-M "init"
Then, you can clone the database remotely. Assume that the IP address of this machine is 192.168.1.1. On another machine,
Git clone git@192.168.1.1: testgit
The clone is successful. In this way, the GIT + SSH service in Windows is successful!

Finally, we will explain the limitations that we currently know:
1) link cannot be used, that is, all files must be stored in the GIT user's home. The location of this home is c: \ ICW \ home \ git.
2) the absolute path cannot be used for clone, but the relative path relative to the GIT user home can only be written.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.