202

Host your own git repository at home – Own your bits

 6 years ago
source link: https://ownyourbits.com/2017/08/03/host-your-own-git-repository-at-home/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Host your own git repository at home – Own your bitsSkip to content

While Github is a great way of sharing your project and cooperating with others, often times you would like to have stuff such as your code or configuration files under version control.

You can setup a Gitlab service at home if you want to be in control of your central repository, but unless you are going to be colaborating with a team it can be an overkill and somewhat time consuming to install and configure.

I like having my private config files and scripts at home in my Raspberry Pi, so that I can synchronize my configurations, aliases and scripts between my desktop, laptop, other raspberries and my PC at work. Github allows private repos, but why would I share details about my systems, users and networks with a third party?

Once you have this setup in place, you can even automate backups of your configuration using etckeeper.

Basic overview

edit: you also need a runinng SSH daemon

Setting up a private git repository is almost too simple.

  1. Log in into your Raspberry Pi.
  2. Install the git package
  3. Create a git user
sudo adduser --gecos "" git

That’s it! You can now create a bare repository in your Pi, owned by the git user

mkdir -p /media/USBdrive/git/myrepo.git
sudo chown -R git:git /media/USBdrive/git
cd /media/USBdrive/git/myrepo.git
git init --bare

And access it from outside. Say your hostname, IP or domain for your Raspberry Pi is server

git clone ssh://git@server/media/USBdrive/git/myrepo.git

Final setup

Of course this is a bit too simple. We want a little extra security.

If you haven’t already, generate the SSH keys for the device that you want to access the repo

ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa

Register your public key with the git repository

ssh-copy-id git@server

, which is equivalent to

cat ~/.ssh/id_rsa.pub | ssh git@server "cat >> ~/.ssh/authorized_keys"

Disable login sessions and password for git user, so only users in authorized_keys can access

sudo passwd -l git

Finally, use git-shell for the user git as a limited shell for git operations only.

sudo usermod -s /usr/bin/git-shell git

That’s it! You now have a secure, self-hosted git repository. Easy!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK