Wednesday, July 15, 2015

Your own private git remote

I have some documents (writing, financial data, some code) that I want to keep private. This describes how to setup a git remote repository on your home network, and to back it up to the cloud (daily) with tarsnap.

Definitions:

office
The host that holds your remote git repo.
lap
The computer where you do your programming.

Here are the steps:

  1. Create a git-private user on office. On OpenBSD, that is
    adduser git-private
  2. Create ssh key-pair on lap
    mark@lap:~$ ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/mark/.ssh/id_rsa): /home/mark/.ssh/id_rsa_git-private
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /home/mark/.ssh/id_rsa_git-private.
    Your public key has been saved in /home/mark/.ssh/id_rsa_git-private.pub.
    The key fingerprint is:
    cc:c7:c8:ab:36:9b:1a:d1:61:d1:2f:9a:06:4b:97:16 mark@lap
    The key's randomart image is:
    +--[ RSA 2048]----+
    |      ..         |
    |      E..        |
    |      oo .       |
    |    oo+=.o.      |
    |   ..=.oS.o      |
    |    ..+  o       |
    |    ..  .        |
    |     .oo         |
    |    .o+o         |
    +-----------------+
    mark@lap:~$
    
  3. Authorize key.
    scp ~/.ssh/id_rsa_git-private.pub git-private@office:~/.ssh/authorized_keys
  4. On lap, associate private key with office
    cat >> ~/.ssh/config
    Host            office
     Hostname office
     IdentityFile    ~/.ssh/id_rsa_git-private
     User            git-private
    ^D
    
  5. Set up bare remote git repo on office.
    mark@lap:~$ ssh git-private@office
    git-private@office:~$ git init --bare myrepo.git
    
  6. On lap, add remove repo as remote.
    mark@lap:~$ git remove -v
    mark@lap:~$ git remote add origin git-private@prod:/home/git-private/myrepo.git
    mark@lap:~$ git push -u origin all
    
  7. To securely backup encrypted versions of your remove, see my Recipe for setting up backups with tarsnap (OpenBSD 5.7).

No comments:

Post a Comment