Skip to end of metadata
Go to start of metadata

Git is a part of CentOS 7 repository, so you can install it easily by yum.

Configure Git Server on CentOS 7

Server

$ yum install git-core
$ sudo useradd git
$ sudo passwd git


Client (Local Machine)

$ ssh-keygen -t rsa
$ cat ~/.ssh/id_rsa.pub | ssh git@remote-server "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"


Server

$ sudo su git
$ mkdir -p /home/git/project-1.git
$ cd /home/git/project-1.git
$ git init --bare

Initialized empty Git repository in /home/git/project-1.git
Client (Local Machine)

$ mkdir -p /home/user/dev/project
$ cd /home/user/dev/project
$ git init


Initialized empty Git repository in /home/user/dev/project

$ git add . // Normal work with git
$ git commit -m "blah blah"
$ git remote add origin git@remote-server:project-1.git
$ git push origin master
if git server asks for password then review /var/log/secure in server

Server

$ tail -f /var/log/secure
and search for

Authentication refused: bad ownership or modes for directory /home/git/.ssh
or
Authentication refused: bad ownership or modes for file /home/git/.ssh/authorized_keys
To solve this problem we need to change mode and permission of .ssh folder and authorized_keys file

Server

$ sudo su git
$ chmod 600 /home/git/.ssh
$ chmod 700 /home/git/.ssh/authorized_keys
$ systemctl restart sshd.service // restart ssh service
and push again

Client

$ git push origin master