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 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.
$ ssh-keygen -t rsa -C “email@example.com”
Now it is needed to copy the public key to the server, to do this simply type below command.
Note that you need to change id_rsa.pub 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.
cat id_rsa.pub >> /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
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
git init .
git add .
git commit -m ‘first’
git remote add origin gituser@domain:test_repo.git
git push origin master
Clone your repo
Pull your newest version from your repo
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.