Git - gpunalkar/devops GitHub Wiki
Server Side Configuration
- 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
- 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
- Remote Repository Creation
- mkdir /repositories/git_repo1.git
- cd /repositories/git_repo1.git
- git init --bare --shared=group
- sudo chgrp -R git_users .
- 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
-
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.
-
Open Git Bash and generate public/private key pair using the following command:
- ssh-keygen -t rsa -C "[email protected]"
- Copy the contents of the public key file (by default: path_to_key/id_rsa.pub)
Server Side Configuration (continued)
- 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
- 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
- Create another folder and clone the remote repository to this folder:
- mkdir test2
- cd test2
- git clone [email protected]:git_repo1.git .
- ls