This is the ad hoc tutorial on how to setup remote GIT repository server on CentOS 7.
Below content is complementary to the video tutorial above.
Server Side Configuration
1. Initial Configuration
Update the system and install some standard utilities
yum -y install nano
Install Git and enable Git shell
echo "/bin/git-shell" >> /etc/shells
Create new group for Git users and specify passwordless authentication for this group:
Add the following lines to /etc/ssh/sshd_config
PasswordAuthentication no
Restart SSH service
Create new folder to hold the future git remote repositories:
2. User Management
Create a Git user and authorized_keys file to hold SSH public keys:
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
3. Remote Repository Creation
cd /repositories/git_repo1.git
git init --bare --shared=group
sudo chgrp -R git_users .
4. SSH Authorization and Access Management
Provide access for git_user1 to repository git_repo1:
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:
3. Copy the contents of the public key file (by default: path_to_key/id_rsa.pub)
Server Side Configuration (continued)
5. Use the following commands to authorize your public key for the previously created user:
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):
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 git_user1@192.168.70.136:git_repo1.git
git push origin master
2. Create another folder and clone the remote repository to this folder:
cd test2
git clone git_user1@192.168.70.136:git_repo1.git .
ls
Related resources: