captainarkdotnet/output/private-git-repo.html

332 lines
16 KiB
HTML
Raw Normal View History

2016-01-31 13:43:06 +01:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Private git repo</title>
<!-- Bootstrap Core CSS -->
<link href="./theme/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="./theme/css/clean-blog.min.css" rel="stylesheet">
<!-- Code highlight color scheme -->
<link href="./theme/css/code_blocks/github.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<meta property="og:locale" content="">
<meta property="og:site_name" content="Sysadmining. All day. Every day.">
<meta property="og:type" content="article">
<meta property="article:author" content="">
<meta property="og:url" content="./private-git-repo.html">
<meta property="og:title" content="Private git repo">
<meta property="og:description" content="">
<meta property="og:image" content="./">
<meta property="article:published_time" content="2016-01-31 00:00:00+01:00">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="./">Sysadmining. All day. Every day.</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="/">Homepage</a></li>
<li><a href="/categories.html">Categories</a></li>
<li><a href="./pages/about.html">About</a></li>
<li><a href="./pages/resume.html">Resume</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Header -->
<header class="intro-header" style="background-image: url('/bg.png')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-heading">
<h1>Private git repo</h1>
<span class="meta">Posted by
<a href="./author/antoine-joubert.html">Antoine Joubert</a>
on Sun 31 January 2016
</span>
</div>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<!-- Post Content -->
<article>
<h2>Introduction</h2>
<p>I've decided to migrate this blog to <a href="http://blog.getpelican.com/">Pelican</a>. I've been playing around with it over the week-end, and it turns out to be way easier to manage than <a href="https://jekyllrb.com/">Jekyll</a>. Themes are way easier to install and configure, so it ends up looking better as well !</p>
<p>Since I'm basically recreating this blog from scratch, I've decided to delete the old git repo that was hosting it, and to create a new one.</p>
<p>Setting up your own private git repo is pretty easy to achieve and is already well-documented on the <a href="https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server">Git</a> website.</p>
<p>However, since every time I want to create a new repo , I end up have to look for that page since I've had time to forget how to do it, I figured I'd write a few lines on the subject.</p>
<p>In this tutorial, I'll configure a git repo on a distant server running Debian 8 (Jessie). This repo will be remotely accessible using SSH. Two users will be able to connect to it : me and the www-data user on my webserver.</p>
<h2>SSH keys</h2>
<p>If you don't have one already, you'll need a ssh-key to connect to the git repo.</p>
<p>On your computer, in a shell, as your usual user :</p>
<div class="highlight"><pre>ssh-keygen -t rsa -b 3072
Generating public/private rsa key pair.
Enter file in which to save the key <span class="o">(</span>/home/user/.ssh/id_rsa<span class="o">)</span>:
Enter passphrase <span class="o">(</span>empty <span class="k">for</span> no passphrase<span class="o">)</span>:
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/id_rsa.pub.
The key fingerprint is:
<span class="o">[</span>Redacted<span class="o">]</span>
</pre></div>
<p>For security reasons, configuring a passphrase is recommanded. On Mac OS X and most desktop environnements on Linux, you can store this passphrase for the duration of your session using the <code>ssh-add</code> command.</p>
<p>On the server, we also have to create a ssh-key for the user that is running our webserver (you'll need to have sudo installed on your server) :</p>
<div class="highlight"><pre>sudo -H -u www-data ssh-keygen -t rsa -b 3072
Generating public/private rsa key pair.
Enter file in which to save the key <span class="o">(</span>/var/www/.ssh/id_rsa<span class="o">)</span>:
Enter passphrase <span class="o">(</span>empty <span class="k">for</span> no passphrase<span class="o">)</span>:
Enter same passphrase again:
Your identification has been saved in /var/www/.ssh/id_rsa.
Your public key has been saved in /var/www/.ssh/id_rsa.pub.
The key fingerprint is:
<span class="o">[</span>Redacted<span class="o">]</span>
</pre></div>
<p>If you decide to configure a passphrase for that ssh-key, you'll have to type it every time you'll want to pull from your repo.</p>
<h2>Server management</h2>
<p>First thing first, we have to install the git package on the server that will be hosting the git repo :</p>
<div class="highlight"><pre>apt update <span class="o">&amp;&amp;</span> apt install git -y
</pre></div>
<p>Then, we will create a user named git :</p>
<div class="highlight"><pre>useradd -s /usr/bin/git-shell -m -r git
</pre></div>
<p>This will create a system user (UID &lt; 1000) with a /home/git home directory. If you want to host your git repos somewhere else on your filesystem, you should add a <code>-d /home/directory/for/git</code> in the previous command.</p>
<p>This user will also use the git-shell shell. This limits remote connection to that user to git commands (like the rssh shell can limit remote connection to a user to scp or rsync commands).</p>
<p>We have to configure our system to allow the use of this shell :</p>
<div class="highlight"><pre><span class="nb">echo</span> <span class="s1">&#39;/usr/bin/git-shell&#39;</span> &gt;&gt; /etc/shells
</pre></div>
<p>We now need to create the .ssh/authorized_keys file for the git user with the correct permissions :</p>
<div class="highlight"><pre>sudo -H -u git mkdir /home/git/.ssh <span class="o">&amp;&amp;</span> chmod <span class="m">700</span> /home/git/.ssh
sudo -H -u git touch /home/git/.ssh/authorized_keys <span class="o">&amp;&amp;</span> chmod <span class="m">600</span> /home/git/.ssh/authorized_keys
</pre></div>
<p>You can now copy the content of the two $HOME/.ssh/id_rsa.pub files we've created earlier using the <code>ssh-keygen</code> command in /home/git/.ssh/authorized_keys.</p>
<p>The last thing we have to do is to create our first git repo. In this example, my project will be called 'captainarknet' as it will be hosting this blog :</p>
<div class="highlight"><pre>sudo -H -u git mkdir /home/git/captainarknet.git
<span class="nb">cd</span> /home/git/captainarknet.git
sudo -H -u git git init --bare
</pre></div>
<p>The last command should give you the following output :</p>
<div class="highlight"><pre>Initialized empty Git repository in /home/git/captainarknet.git/.git/
</pre></div>
<p>We're done with the server configuration. Let's now actually push stuff to our repo !</p>
<h3>Initial push</h3>
<p>The files for my blog are store in the ~/Documents/projects/captainarknet on my computer. Before doing anything else, we first have to make sure that we currently are in that folder :</p>
<div class="highlight"><pre><span class="nb">cd</span> ~/Documents/projects/captainarknet
</pre></div>
<p>Let's now push the content of that folder to our repo :</p>
<div class="highlight"><pre>git init
git add .
git commit -m &#39;initial commit&#39;
git remote add origin git@git.captainark.net:captainarknet.git
git push origin master
</pre></div>
</article>
<hr>
<div class="sharing">
</div>
<hr>
<div class="comments">
<h2>Comments !</h2>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'captainark';
var disqus_identifier = 'private-git-repo.html';
var disqus_url = './private-git-repo.html';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//captainark.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the comments.</noscript>
</div>
</div>
</div>
</div>
<hr>
<!-- Footer -->
<footer>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<ul class="list-inline text-center">
<li>
<a href="mailto:contact@captainark.net">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-envelope fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://twitter.com/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://github.com/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-github fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href=" https://www.facebook.com/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://plus.google.com/+CaptainarkNet47">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-google-plus fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://www.youtube.com/user/thecaptainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-youtube fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://steamcommunity.com/id/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-steam fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="http://www.twitch.tv/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-twitch fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="http://www.last.fm/user/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-lastfm fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
</ul>
<p class="copyright text-muted">
Blog powered by <a href="http://getpelican.com">Pelican</a>,
which takes great advantage of <a href="http://python.org">Python</a>.
</p> </div>
</div>
</div>
</footer>
<!-- jQuery -->
<script src="./theme/js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="./theme/js/bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="./theme/js/clean-blog.min.js"></script>
<script type="text/javascript">
var disqus_shortname = 'captainark';
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = '//' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
</body>
</html>