Skip to content

Instantly share code, notes, and snippets.

@thegeek
Created April 24, 2018 07:39
Show Gist options
  • Save thegeek/ae5d396766b3e477e9dc2bca3abf16d5 to your computer and use it in GitHub Desktop.
Save thegeek/ae5d396766b3e477e9dc2bca3abf16d5 to your computer and use it in GitHub Desktop.
Git Server CentOS 7

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment