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.
Pingback: Eigenes, sicheres Git-Repository erstellen
I cloned my folder from a public git rep, so now, my repo is already a git. Can you suggest a way to:
I tried using http://qugstart.com/blog/ruby-and-rails/create-a-new-git-remote-repository-from-some-local-files-or-local-git-repository/ but it fails, since my repo is already a git branch.
You should be able to just create a new repository on the server as talked about above. Then from your folder, run something like:
So if your trying to add the repository project to the server server as the (remote server) user user, you would add:
After adding the remote repository information to the config, to push the data run:
1. The name of my branch is core-models (not master). So I suppose I have to add that name.
2. I think, I have to issue “git remote rm origin”, since the origin for my branch is already set-up. Right?
3. When I follow your example: it works. Can you tell, how can another user (or myself) clone from that repo (int the example above)? Assuming the location is myuserid@spmi.home.univname.edu:new-project.git
4. After following your example, my own project works. Only thing remaining is question in the 3 above.
1. Yes, you should use whatever your branch name is.
2. if may remove the origin config, as you describe above, or you may add a new one (just named different).
3. Your other users should be able to download via the same link you added in my previous example. They will need an SSH account on your server, or use a generic account.
Thanks a lot. It works fine.
Meanwhile I have also learnt git by your help.
Good
I am glad I could be of some help.
I wasn’t able to push to the remote server from my local machine
fatal: Unable to create temporary file: Permission denied
fatal: sha1 file ” write error: Invalid argument
We have to create the git user from a priveledged account, and then create the .git folder (also as the root user?) But your instrux don’t mention changing permissions on anything.
Should they?
What have I missed?
Yah, that was it.
I should have known better.. but didn’t catch the inferrance that the git user needed to create (and own) the .git folder (and subsequently everything inside of it.)
I chown/chgrp’d my way through it though…