Setting Up Own Git Server On CentOS

Recently I needed a private git server and since I have a vps, I tried to set up one on my centos 5 machine.

First let’s start with creating users, group on server and rsa key pair on local to use ssh login.

After these, create a new repo on server, and commit & push & pull to/from git server.

Creating git user, group and rsa key pair for ssh

After opening terminal on mac/linux dist. or putty on windows, I started by creating a clean new user for my git account, lets say @gituser.
After creating that user, I created a “devs” group and assigned gituser to devs group. See below.

$ sudo groupadd devs
$ sudo useradd -G devs -d /home/gituser-m -s /bin/bash gituser
$ sudo passwd gituser

After user group and users created on centos machine, lets create a new rsa key pair (public/private) to be able to access server via ssh.

$ cd ~/.ssh
$ ssh-keygen -t rsa -C “”

Now it is needed to copy the public key to the server, to do this simply type below command.

$ ssh-copy-id -i ~/.ssh/ gituser@server_ip

Note that you need to change file location according to yours and username and server ip.

If you get a “command not found” error for ssh-copy-id command, you need to execute below 3 commands.

scp ~/.ssh/ gituser@server_ip:./
ssh gituser@server_ip
cat >> /home/gituser/.ssh/authorized_keys

If everything is ok till here, now you should login your server in your machine without any pass.

Creating git repo, committing and pulling changes

Login your server and start typing creating and initializing commands.

Create & Init git repo

mkdir test_repo.git
cd test_repo.git
git –bare init

Now your first repo is created and initialized.
Exit from your server, and commit your project.

Create local project and commit project

mkdir test_repo
cd !$
git init .
touch README
git add .
git commit -m ‘first’
git remote add origin gituser@domain:test_repo.git
git push origin master

Clone your repo

git clone gituser@domain:test_repo.git

Pull your newest version from your repo

cd test_repo
git pull

That’s it for now. There are lots of git commands, check gitref for details.

I wrote this post that’s because I spent some time to copy my rsa public key to server (because ssh-copy-id not found on my mac) and some other stuff.

P.S: If there is no special reason I highly recommend getting a private plan on github. Plans start from $7 and you get really great service.


Tags: , , ,

Comments: 3

Leave a reply »

  • superb post.Never knew this, appreciate it for letting me know.

  • Hello.This post was really remarkable, especially because I was browsing for thoughts on this topic last week.

  • Thanks for this tremendous post, I am glad I noticed this website on yahoo.

  • Leave a Reply
    Your gravatar
    Your Name