About the Blog

Its about anything and everything. I, Steven Hancock started this blog for a variety of reasons. I want to start documenting my life and sharing that with others, whether that's family, friends, strangers or my future self. I also want to start sharing my experiences with others in hopes that others can learn from me. Perhaps I can help someone set up an Ubuntu server, write a Django Web Application, or setup a Phonegap Mobile App.

That's it. I'm hear to share. Nothing more, nothing less. I will be covering a wide variety of topics so feel free to browse for the blog entries that interest you most.

Setting up an Ubuntu Git Server

May 7, 2013

I've been intending on setting up a version control system for a while now. I'm in need of something that would house some of my personal projects, like this blog. I have lots of experience with Subversion, I've set up numerous servers and clients for work and school. SVN is fine and dandy. It has always served me well. However I keep hearing great things about this GIT thing. I used GitHub for a school project a couple of years ago. GitHub fulfilled its purpose well. It hosted the files, allowed for easy user setup & management, and worked as our version control system. Since the project only lasted a month or so, I didn't really get to dive into GIT as much as I would have liked. So I've decided to set up a GIT server in hopes that I gain some more knowledge about GIT. I will also admit that my server is a 6 or 7-year-old computer. It could die at any time so a distributed version control system should suit my needs very well.

Below is a step-by-step instruction guide on how I set up my GIT Server on Ubuntu 12.04, and GIT clients on Mac OS X, Windows 8, and an Ubuntu instance on Amazon's EC2.

Server Setup

Install git & ssh-server

$ sudo apt-get install openssh-server git-core

Create a git user that will be used by clients. Fill out the required elements (such as a password).

$ sudo adduser git

Switch to the git user and prepare for allowing password-less login through SSH.

$ sudo su git
$ cd ~
$ mkdir .ssh

Make sure that the git user is able to login through SSH. The .ssh folder will house the authorized_keys file that will contain all of the client generated ssh keys.

Set up the git repository on the server.

$ mkdir randomscribes.git
$ cd randomscribes.git
$ git --bare init

Your git server is ready for client requests. For some added security you may want to look into the package called git-shell. Git-shell will help restrict the git user to only commands required for git.

Mac OS X Client

Generate an ssh-key so we don't have to enter a password every time we make push/pull requests.

$ ssh-keygen -t rsa
#Call it whatever you want (I called mine git_rsa)
$ more ~/.ssh/git_rsa.pub
#Protect your ssh public key
$ chmod 400 ~/.ssh/git_rsa.pub

Copy everything that is in git_rsa.pub. You'll want to add this string to the end of your server's git user's ~/.ssh/authorized_keys file.

Create an SSH alias on the client so we can easily access the server.

$ nano ~/.ssh/config

Enter the alias.

Host git_server
User git
Hostname stevenhancock.ca
IndentityFile ~/.ssh/git_rs

Download & install GIT from http://git-scm.com/downloads. Then open the terminal and start setting git up.

Setup your git's global user and email (helpfull for figuring out who made what changes).

$ git config --global user.name "Steven Hancock"
$ git config --global user.email stevenhancock@example.com

Prep the filesystem for your project.

$ mkdir randomscribes.git
$ cd randomscribes.git
$ git init
$ git add .

Create something to import into the project.

$ nano README
$ git commit -a -m 'initial commit'
$ git remote add origin git@git_server:/home/git/randomscribes.git
$ git push origin master

That's it, everything should be good to go on the Mac client.

Ubuntu Amazon EC2 Client

Install git & SSH-client.

$ sudo apt-get install git-core ssh-client

Create an ssh key for password-less login and call it whatever you want.

$ ssh-keygen -t rsa

Copy everything that is in rsa.pub. You'll want to add this string to the end of your server's git user's ~/.ssh/authorized_keys file.

$ more ~/.ssh/git_rsa.pub

Create an SSH alias on the client so we can easily access the server.

$ nano ~/.ssh/config

Enter the alias.

Host git_server
User git
Hostname stevenhancock.ca
IndentityFile ~/.ssh/git_rsa

Again, setup your git's global user and email.

$ git config --global user.name "Steven Hancock"
$ git config --global user.email stevenhancock@example.com

Now cd into the directory that you would like to store the local version of your project and checkout the repository.

$ git clone git@git_server:/home/git/randomscribes.git

And we are good to go. You now have git setup on your EC2 instance.

Windows 8 Client

Download and install Git from http://git-scm.com/downloads.

Open Git Bash and create an ssh key for password-less login and call it whatever you want (I called mine git_rsa).

#If you don't already have an .ssh directory in your user's home folder
$ mkdir ~/.ssh
$ cd ~/.ssh
$ ssh-keygen -t rsa

Create a text file called config in your .ssh folder. We are going to create an ssh alias. Place the following text (replacing values as necessary) in the config file.

Host git_server
User git
Hostname stevenhancock.ca
IndentityFile ~/.ssh/git_rsa.ppk

Like with the other clients copy everything that is in rsa.pub. You'll want to add this string to the end of your server's git user's ~/.ssh/authorized_keys file.

Let's setup git.

$ git config --global user.name "Steven Hancock"
$ git config --global user.email stevenhancock@example.com

Now cd into the directory that you would like to store the local version of your project and checkout the repository.

$ git clone git@git_server:/home/git/randomscribes.git

We are done... That was easy.

Resources

  1. http://git-scm.com/book/en/Getting-Started-Installing-Git