epubjs
Version:
Render ePub documents in the browser, across many devices
92 lines (69 loc) • 5.27 kB
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Pro Git - professional version control</title>
<meta content="http://www.w3.org/1999/xhtml; charset=utf-8" http-equiv="Content-Type"/>
<link href="stylesheet.css" type="text/css" rel="stylesheet"/>
<style type="text/css">
@page { margin-bottom: 5.000000pt; margin-top: 5.000000pt; }</style>
</head>
<body class="calibre">
<h2 class="calibre4" id="calibre_pb_33">Setting Up the Server</h2>
<p class="calibre3">Let's walk through setting up SSH access on the server side. In this example, you'll use the <code class="calibre10">authorized_keys</code> method for authenticating your users. We also assume you're running a standard Linux distribution like Ubuntu. First, you create a 'git' user and a <code class="calibre10">.ssh</code> directory for that user.</p>
<pre class="calibre9"><code class="calibre10">$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh
</code></pre>
<p class="calibre3">Next, you need to add some developer SSH public keys to the <code class="calibre10">authorized_keys</code> file for that user. Let's assume you've received a few keys by e-mail and saved them to temporary files. Again, the public keys look something like this:</p>
<pre class="calibre9"><code class="calibre10">$ cat /tmp/id_rsa.john.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCB007n/ww+ouN4gSLKssMxXnBOvf9LGt4L
ojG6rs6hPB09j9R/T17/x4lhJA0F3FR1rP6kYBRsWj2aThGw6HXLm9/5zytK6Ztg3RPKK+4k
Yjh6541NYsnEAZuXz0jTTyAUfrtU3Z5E003C4oxOj6H0rfIF1kKI9MAQLMdpGW1GYEIgS9Ez
Sdfd8AcCIicTDWbqLAcU4UpkaX8KyGlLwsNuuGztobF8m72ALC/nLF6JLtPofwFBlgc+myiv
O7TCUSBdLQlgMVOFq1I2uPWQOkOWQAHukEOmfjy2jctxSDBQ220ymjaNsHT4kgtZg2AYYgPq
dAv8JggJICUvax2T9va5 gsg-keypair
</code></pre>
<p class="calibre3">You just append them to your <code class="calibre10">authorized_keys</code> file:</p>
<pre class="calibre9"><code class="calibre10">$ cat /tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys
$ cat /tmp/id_rsa.josie.pub >> ~/.ssh/authorized_keys
$ cat /tmp/id_rsa.jessica.pub >> ~/.ssh/authorized_keys
</code></pre>
<p class="calibre3">Now, you can set up an empty repository for them by running <code class="calibre10">git init</code> with the <code class="calibre10">--bare</code> option, which initializes the repository without a working directory:</p>
<pre class="calibre9"><code class="calibre10">$ cd /opt/git
$ mkdir project.git
$ cd project.git
$ git --bare init
</code></pre>
<p class="calibre3">Then, John, Josie, or Jessica can push the first version of their project into that repository by adding it as a remote and pushing up a branch. Note that someone must shell onto the machine and create a bare repository every time you want to add a project. Let's use <code class="calibre10">gitserver</code> as the hostname of the server on which you've set up your 'git' user and repository. If you're running it internally, and you set up DNS for <code class="calibre10">gitserver</code> to point to that server, then you can use the commands pretty much as is:</p>
<pre class="calibre9"><code class="calibre10"># on Johns computer
$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin git@gitserver:/opt/git/project.git
$ git push origin master
</code></pre>
<p class="calibre3">At this point, the others can clone it down and push changes back up just as easily:</p>
<pre class="calibre9"><code class="calibre10">$ git clone git@gitserver:/opt/git/project.git
$ vim README
$ git commit -am 'fix for the README file'
$ git push origin master
</code></pre>
<p class="calibre3">With this method, you can quickly get a read/write Git server up and running for a handful of developers.</p>
<p class="calibre3">As an extra precaution, you can easily restrict the 'git' user to only doing Git activities with a limited shell tool called <code class="calibre10">git-shell</code> that comes with Git. If you set this as your 'git' user's login shell, then the 'git' user can't have normal shell access to your server. To use this, specify <code class="calibre10">git-shell</code> instead of bash or csh for your user's login shell. To do so, you'll likely have to edit your <code class="calibre10">/etc/passwd</code> file:</p>
<pre class="calibre9"><code class="calibre10">$ sudo vim /etc/passwd
</code></pre>
<p class="calibre3">At the bottom, you should find a line that looks something like this:</p>
<pre class="calibre9"><code class="calibre10">git:x:1000:1000::/home/git:/bin/sh
</code></pre>
<p class="calibre3">Change <code class="calibre10">/bin/sh</code> to <code class="calibre10">/usr/bin/git-shell</code> (or run <code class="calibre10">which git-shell</code> to see where it's installed). The line should look something like this:</p>
<pre class="calibre9"><code class="calibre10">git:x:1000:1000::/home/git:/usr/bin/git-shell
</code></pre>
<p class="calibre3">Now, the 'git' user can only use the SSH connection to push and pull Git repositories and can't shell onto the machine. If you try, you'll see a login rejection like this:</p>
<pre class="calibre9"><code class="calibre10">$ ssh git@gitserver
fatal: What do you think I am? A shell?
Connection to gitserver closed.
</code></pre>
</body>
</html>