Creating a secure git repository server is a pretty simple process. Basically we will be using SSH to transmit the data over an encrypted channel. SSH will handle all the authentication and data encryption. So the first set is creating a user for git to use and creating the git users ssh key.
On your server, from a privileged account, create a user (were going to use git).
adduser git
passwd git
The configuration we will be setting up will store the actual repositories in the git users home directory. If you don’t like it’s current location, you may modify the /etc/passwd file for your user.
Once we have the user setup, in it’s home directory we need to create our first repository. Start out by creating the folder, then well go into it and create the git repository files.
mkdir new-project.git
cd new-project.git
git init --bare
With the repository now setup go back to your desktop/laptop system (linux/unix).
From your desktop system, create a empty repository or go to an existing git repo. If you are going to be adding an existing repo, it may not be connected to any other remote repository. if you clone it from a remote source (a directory on the same system counts as a remote source) you will need to modify the repository’s config file and remove those entry’s, look in the config file under the .git (note the ‘dot’) directory.
To create an empty repository, create a directory for the repository, go into it and init the repo.
mkdir new-project.git
cd new-project.git
git init
Since you need something in your repo, and git likes having a readme file (or gitweb dose) let’s create a readme file and commit it.
touch README
git add README
git commit -m 'Added README file, first commit'
Now that we have a commit in our repo, we can add the newly created git repo server and push our new repo to it.
We will start by adding the server to the repo’s configuration.
git remote add origin git@new-git-server.example.com:new-project.git
The above example assumes you’re server’s name is “new-git-server.example.com” and your using a project named “new-project.git” for the user “git”. But it also assumes that your repo is directly in the user git’s home directory. If you store your repo’s in a different directory, you will need to add the list folders after the colon.
After you have successfully added the server, push your new repository to the server.
git push origin master
You may now be asked for the git user’s password, enter it, and your repository should be transferred.
Also check out how to setup a ssh public/private key where no password is required, only the private key on your client system.
The above may look like a lot, but it’s really pretty simple to setup. If you have any problems or questions abut this How-To, please leave a comment or contact me.