summaryrefslogtreecommitdiff
path: root/www/posts/atom.xml
diff options
context:
space:
mode:
Diffstat (limited to 'www/posts/atom.xml')
-rw-r--r--www/posts/atom.xml36
1 files changed, 35 insertions, 1 deletions
diff --git a/www/posts/atom.xml b/www/posts/atom.xml
index c8a3a38..79f3a7c 100644
--- a/www/posts/atom.xml
+++ b/www/posts/atom.xml
@@ -4,8 +4,42 @@
<id>https://davidtsadler.com/posts/atom.xml</id>
<link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/index.html"/>
<link rel="self" type="application/atom+xml" href="https://davidtsadler.com/posts/atom.xml"/>
- <updated>2021-05-28T12:00:00Z</updated>
+ <updated>2021-05-29T12:00:00Z</updated>
<entry>
+ <title type="text">Setting up a Self Hosted Git Server</title>
+ <id>https://davidtsadler.com/posts/git/2021-05-29/setting-up-a-self-host-git-server/index.html</id>
+ <link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/git/2021-05-29/setting-up-a-self-host-git-server/index.html"/>
+ <author><name>David T. Sadler.</name></author>
+ <published>2021-05-29T12:00:00Z</published>
+ <updated>2021-05-29T12:00:00Z</updated>
+ <content type="html">&lt;h1&gt;Setting up a Self Hosted Git Server&lt;/h1&gt;&lt;blockquote&gt;Sat 29th May 2021 By David T. Sadler.&lt;/blockquote&gt;&lt;p&gt;I've always liked the idea of self hosting some of my git repositories. After a bit of research I found that it involves.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Installing git.&lt;/li&gt;&lt;li&gt;Creating a git user.&lt;/li&gt;&lt;li&gt;Setting up ssh so that I can log into the sever securely as the git user.&lt;/li&gt;&lt;li&gt;Creating a test repository on the server.&lt;/li&gt;&lt;li&gt;Creating a test project on my local machine.&lt;/li&gt;&lt;li&gt;Pushing the test project to the git sever.&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Installing Git&lt;/h2&gt;&lt;p&gt;Since its an Ubuntu server installing git is as simple as.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;shell&quot;&gt;$ sudo apt install git-core&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;Creating a User&lt;/h2&gt;&lt;p&gt;The git user will serve two purposes.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The repositories will be stored in the user's home directory.&lt;/li&gt;&lt;li&gt;The user account will contain the public ssh keys of remote users that can access the repositories.&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;shell&quot;&gt;$ sudo adduser --system --shell /usr/bin/git-shell --group --disabled-password --home /home/git git&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;--system Creates a system user user. Not strictly required but since this is not a normal user account I prefer to use this option.&lt;/li&gt;&lt;li&gt;--shell /usr/bin/git-shell Restrict the git user to only git related activities. This also prevents remote users from obtaining a shell by logging in via ssh. Note that git-shell does not prevent normal git operations, such as pull and push, from working over ssh.&lt;/li&gt;&lt;li&gt;--group Creates a group that is the same name as the user.&lt;/li&gt;&lt;li&gt;--disabled-password Prevent logging in with a password. The use of ssh keys is still allowed.&lt;/li&gt;&lt;li&gt;--home /home/git The home directory for the user.&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Setting up SSH&lt;/h2&gt;&lt;p&gt;On my local machine git will use ssh to connect to the remote server as the git user. In order to do this I will need to copy my public ssh key to the git user account.&lt;/p&gt;&lt;p&gt;The below commands create the required .ssh directory and authorized_keys file with the correct permissions.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;shell&quot;&gt;$ sudo mkdir /home/git/.ssh
+$ sudo chown git:git /home/git/.ssh
+$ sudo chmod 700 /home/git/.ssh
+$ sudo touch /home/git/.ssh/authorized_keys
+$ sudo chown git:git /home/git/.ssh/authorized_keys
+$ sudo chmod 600 /home/git/.ssh/authorized_keys&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now I can copy the public ssh key of anyone who needs access to the repositories. There are a few ways of doing this and I tend to just edit the authorized_keys file and manually copy and paste the keys into it. &lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;shell&quot;&gt;$ sudo vim /home/git/.ssh/authorized_keys&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note that to prevent ssh port forwarding via the git user account I prepend the no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty options to the key.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;shell&quot;&gt;$ sudo cat /home/git/.ssh/authorized_keys
+
+no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa
+AAAAB3NzaC1yc2EAAAADAQABAAABAQCB007n/ww+ouN4gSLKssMxXnBOvf9LGt4LojG6rs6h
+PB09j9R/T17/x4lhJA0F3FR1rP6kYBRsWj2aThGw6HXLm9/5zytK6Ztg3RPKK+4kYjh6541N
+YsnEAZuXz0jTTyAUfrtU3Z5E003C4oxOj6H0rfIF1kKI9MAQLMdpGW1GYEIgS9EzSdfd8AcC
+IicTDWbqLAcU4UpkaX8KyGlLwsNuuGztobF8m72ALC/nLF6JLtPofwFBlgc+myivO7TCUSBd
+LQlgMVOFq1I2uPWQOkOWQAHukEOmfjy2jctxSDBQ220ymjaNsHT4kgtZg2AYYgPqdAv8JggJ
+ICUvax2T9va5 gsg-keypair&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;On my local machine I can test ssh access.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;shell&quot;&gt;$ ssh git.davidtsadler.com
+
+fatal: Interactive git shell is not enabled.
+hint: ~/git-shell-commands should exist and have read and execute access.&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The message that comes back indicates that ssh is working and that the git-shell is been used.&lt;/p&gt;&lt;h2&gt;Creating a Test Repository&lt;/h2&gt;&lt;p&gt;An empty repository is setup by running git init with the --bare option. I also ensure that the git user owns the repository and that main will be the default branch when its checked out.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;shell&quot;&gt;$ sudo git init --bare /home/git/test.git/
+$ sudo chown -R git:git /home/git/test.git/
+$ sudo git --git-dir=/home/git/test.git/ symbolic-ref HEAD refs/heads/main&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;Creating a Test Project&lt;/h2&gt;&lt;p&gt;Back on my local machine I can create a test project and push it to the remote server.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;shell&quot;&gt;$ mkdir test
+$ cd test
+$ git init
+$ touch readme
+$ git add .
+$ git commit -m 'Initial commit'
+$ git remote add origin git@git.davidtsadler.com:/home/git/test.git
+$ git push origin main&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I can also test that I can clone the repository.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;shell&quot;&gt;rm -rf test
+git clone git@git.davidtsadler.com:/home/git/test.git&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Links&lt;/h3&gt;&lt;a href=&quot;/posts/git/&quot;&gt;Git - Read More Posts.&lt;/a&gt;&lt;p&gt;I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.&lt;/p&gt;&lt;a href=&quot;mailto:david@davidtsadler.com&quot;&gt;Email david@davidtsadler.com&lt;/a&gt;&lt;h3&gt;License&lt;/h3&gt;&lt;a href=&quot;https://creativecommons.org/licenses/by-sa/4.0/&quot;&gt;The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.&lt;/a&gt;&lt;p&gt;Copyright © 2021 David T. Sadler.&lt;/p&gt;&lt;a href=&quot;/&quot;&gt;Return to Homepage.&lt;/a&gt;</content>
+</entry><entry>
<title type="text">Pre and Post Validation Hooks with Certbot</title>
<id>https://davidtsadler.com/posts/letsencrypt/2021-05-28/pre-and-post-validation-hooks-with-certbot/index.html</id>
<link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/letsencrypt/2021-05-28/pre-and-post-validation-hooks-with-certbot/index.html"/>