Git remote hosting on Ubuntu

Git is a powerful version control software. I tried to host it on linux server, and develop on windows.

Note: 1. Use putty to generate ssh keys, instead of linux ssh-keygen. It's not to say you can't use linux to generate, it's merely to say it's more convenient to use putty in this case.

Requirement:
1. Server: ubuntu 11.10.
2. client: windows 7.
3. Install git on ubuntu (this is normally by default with ubuntu installation, and it's quite easy to install if not yet).
4. Install git extension on Windows client. This GUI program integrates nicely with Visual Studio 2010.
5. Install putty on windows client. This is not necessary, but convenient, because sometimes, we just want to login ubuntu for a moment.

Steps:
First, we need to generate ssh key pair to authenticate client on server.
1. Generate ssh key pair using putty key generator. This is possible through standalone putty, or use the key generator coming with git extension.
2. Save the private key to a client folder. Copy the public key and paste it to an empty file with same name as private key, and with .pub extension name.
3. Finding it's difficult to directly copy/paste between server and client, I use email to transfer the public key from client machine to server. (use root access ftp is more easier to upload files to ubuntu.)
4. On server, move the saved public key to your .ssh folder under your home directory.
5. On server, append this public key to your authorized_keys file in the .ssh folder.
6. Try to login to ubuntu from client's putty, using the private key. Successful login shows server is able to authenticate client machine.

Now comes the git part.
On client side:
7. Assuming git extension is up and running, we go to manage remote repository within git extension.
8. Normally use the name origin.
9. Url here is a key step: ssh://usernameonserver@servernameorip:/remoterepositorylocation. This is worth a little explanation.
(1) first part: ssh. This indicates we're going to use ssh protocal for this repository. There're several protocols git supports. Normally for read-write access, we'd use ssh. Github uses git protocol though.
(2) usernameonserver, please enter the username you use to login on server, as this is where git client tries to login to server. A wrong name will be denied access.
separated by "@"
(3) servernameorip, here is to indicate your server location. Both server name (DNS translated), or ip address directly.
separated by ":"
(4) here is the location of the remote repository on that server. Make sure your user has write or read access on that server, otherwise it will create problems for git push or pull.

On server side:
10. Just make sure the client points to a valid remote repository. It should be a bare repository, use git --bare init.
Note:
1. Somewhere in between, putty may give some problems, like key agent refused to add your key, just restart the key agent.
2. In git extension remote repository management, test connection is a good idea to make sure your key is all ready. If protocol and key are configured correctly, test connection should login with key, not with password.
3. git clone and git fetch seems to follow different convention on the servernameorip with remoterepositorylocation. git clone does not have ":", well, git fetch does. But when maintain remote, still need to maintain ":", as git clone does not rely on remote maintenance.

That's it. Enjoy the power of git.

Comments

Popular posts from this blog

Mathematica vs Matlab vs Maple, discuss (Wilmott Forums)