Tuesday, 19 August 2014

Setting up Git repositories


Setting up user based push on Git repositories

1) Create a group for users who would be pushing code to git repository
# groupadd Git_Users

2) Now add this user on the git server and setup his/her password
# useradd mayur
# passwd mayur

3) Any user(for eg., "mayur" here ) who wishes to push the code on to the git repository must be added
to this group.
# usermod -G Git_Users mayur

4) Now assign the appropriate ownerships (Group and owner) to the repositories.
# chown –R  root:Git_Users  <repository>

5) Assign the required read/write permissions to the repository.
# chmod –R 775 <repository> 

6) Edit the /etc/passwd file and add the below entry:
mayur:x:502:502::/home/mayur:/usr/bin/git-shell
Please see #1 in Issues to know more why this is needed.

7) Get openssh server up and running on the server hosting the git repositories.
Yum install openssh-server
/etc/init.d/sshd    [status/start]

8) Git setup on client boxes
8.1 ) Make sure that the same version of git is installed on all systems that try to push the code on to the central git repository.
8.2 ) Set up .gitconfig on all developer boxes. We could provide a shell script to them to set .gitconfig values, particularly username and email.

Issues :

1. User would be able to ssh on to the server now . Disabling login with “/sbin/nologin” in /etc/passwd doesn't work as we get the following error that's spewed by the shell.
fatal: protocol error: bad line length character: This
The above issue was fixed with step#6 described above. Please read.

2. If you are on windows and trying to do a xbased port forwarding for gitk, you may have to
- Install tk on linux box i.e., “yum install tk”
- Install Xming on windows box and then launch “Xlaunch”
- Setup environment variable, DISPLAY and point it to the windows IP where you want to redirect the O/P to.
Example :
export DISPLAY=10.10.8.7:0.0

3. If you have issues redirecting, you may want to list the linux box’s IP in X0.hosts file in your Xming installation directory. This will unblock this IP from letting Xbased port forwarding happen.

4.Does everything work fine ? If you are seeing issues like below,
Error in startup script:     (default value for "-font" in widget ".___tk_set_palette.button")     invoked from within
You may have to install “yum install dejavu-sans-fonts” on the linux box.


  
Things to do:
1) Set up ssh keys for users instead of a password based authentication. Let them create keys and send it to us(for now).
We can then add it to the ~/authorized_keys file. This way they can push the code from anywhere.

Similar to what we do in gerrit...