Git - gpunalkar/devops GitHub Wiki

Server Side Configuration

  1. Initial Configuration
  • Update the system and install some standard utilities
  • yum update -y && yum upgrade -y
  • yum -y install nano

Install Git and enable Git shell

  • yum install -y git
  • echo "/bin/git-shell" >> /etc/shells

Create new group for Git users and specify passwordless authentication for this group:

  • groupadd git_users

Add the following lines to /etc/ssh/sshd_config Match Group git_users PasswordAuthentication no

Restart SSH service

  • service sshd restart

Create new folder to hold the future git remote repositories: mkdir /repositories

  1. User Management Create a Git user and authorized_keys file to hold SSH public keys:
  • useradd -g git_users git_user1
  • mkdir /home/git_user1/.ssh
  • chmod 700 /home/git_user1/.ssh
  • echo ""> /home/git_user1/.ssh/authorized_keys
  • chmod 600 /home/git_user1/.ssh/authorized_keys
  • chown -R git_user1:git_users /home/git_user1/.ssh
  • usermod --shell /bin/git-shell git_user1
  1. Remote Repository Creation
  • mkdir /repositories/git_repo1.git
  • cd /repositories/git_repo1.git
  • git init --bare --shared=group
  • sudo chgrp -R git_users .
  1. SSH Authorization and Access Management

Provide access for git_user1 to repository git_repo1:

  • unlink /home/git_user1/git_repo1.git
  • sudo ln -s /repositories/git_repo1.git /home/git_user1/
  • chown -R git_user1:git_users /home/git_user1

Client Side Configuration

  1. Download and install Git from https://git-scm.com/downloads. We will need Git bash tool to generate public/private key pair and to establish ssh connection to the server.

  2. Open Git Bash and generate public/private key pair using the following command:

  1. Copy the contents of the public key file (by default: path_to_key/id_rsa.pub)

Server Side Configuration (continued)

  1. Use the following commands to authorize your public key for the previously created user:
  • usersPubKey='contents_of_your_public_key_file'
  • echo $usersPubKey > /home/git_user1/.ssh/authorized_keys

Testing

  1. Create new folder on the client side, initialize git here and push it to git repository server (replace username and git server address and repo name with your own):
  • mkdir test1 && cd test1
  • git init .
  • git config --global user.email "[email protected]"
  • git config --global user.name "Your Name"
  • echo test_content1 > test1.txt
  • echo test_content2 > test2.txt
  • git add .
  • git commit -m "initial commit"
  • git remote add origin [email protected]:git_repo1.git
  • git push origin master
  1. Create another folder and clone the remote repository to this folder: