DBA knowledge,standing on the shoulders of giants.
Setting Up the Git Server
July 13, 2016
GITHUB is a free and open source public code repository, from small to big project. Many developers are using GitHub everyday, even me, although I’m not a coder. But because of its open source, everyone can visit your code, including sensitive data. Based on this, many develop teams will build their own git server. This post will show you how to build a git server on Linux platform.
Setup ssh keys for authentication
With ssh keys authentication, there’s no web interface for git server management. And for safety, it’s recommended to disable git user login with ssh. The first step we should do is creating a git user, setting up the ssh keys for authentication, and disabling git user for ssh login.
Generate the ssh key from you local user, and put the ssh keys to git server.
# On the clientssh-keygen-C"admin@oracle ma.com"# On the server with git usermkdir.ssh&&chmod700.sshtouch.ssh/authorized_keys&&chmod600.ssh/authorized_keys# scp the authentication to git serverscp.ssh/id_rsa.pubgit@node1:~/.ssh/authorized_keys
Disable ssh login
On the server end, disable shell login for git user.
usermod -s /usr/bin/git-shell git
Setting remote repository
On the server, I created a directory for my project.
Repository created by git init are called working directories. Working directories will include two type of files, one is your real project files, another is the .git file folder contains the git configuration information about the repository, that is metadata of git repository.
But with git init --bare, it creates bare repositories, which only contains metadata of git repository. And do not have a .git file in the bare repositories. For initializing remote repository or git server, it’s recommended to use --bare options.
With the working directory, we need to modify the git configuration first.
# Adding below line to remote repository if we're using working directory on git server$ tail -2 .git/config
After we pushed from the local to remote, if you want to see the changes on the git server, you need to run git reset --hard HEAD command.
Using git server from local machine
Assume my local repository is /worktmp/git-tutorial.