As a developer, if you do not want to restrict yourself with paid or limited numbers of private repos in services like Github and Bitbucket, it would be desirable to set up your own private git server. This post aims to provide a step-by-step instruction to setting up a private git server.
Add user at the server
Generate public and private keys
Set up public key on the server
Set up private key locally
Create bare repo on the server
Add remote to local repo and push
Add more users
To add more users, you simply need to put more public keys into ~/.ssh/authorized_keys.
Limit git user privilege
To limit git users to only push and pull operations, we can change the shell of user git to git-shell.