From d8153a70dccc678d854ee0ff55bebe71f7c4417a Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Mon, 17 May 2021 16:18:29 -0600 Subject: new blogging system pyssg --- blog/dst/a/git_server_with_cgit.html | 101 ++++++++++------------------------- 1 file changed, 29 insertions(+), 72 deletions(-) (limited to 'blog/dst/a/git_server_with_cgit.html') diff --git a/blog/dst/a/git_server_with_cgit.html b/blog/dst/a/git_server_with_cgit.html index c625eb6..9249326 100644 --- a/blog/dst/a/git_server_with_cgit.html +++ b/blog/dst/a/git_server_with_cgit.html @@ -3,7 +3,7 @@ - Luévano's Blog + Create a git server and setup cgit web app (on Nginx) -- Luévano's Blog @@ -62,103 +62,69 @@

Create a git server and setup cgit web app (on Nginx)

- -

My git server is all I need to setup to actually kill my other server (I've been moving from servers on these last 2-3 blog entries), that's why I'm already doing this entry. I'm basically following git's guide on setting up a server plus some specific stuff for (btw i use) Arch Linux (Arch Linux Wiki: Git server and Step by step guide on setting up git server in arch linux (pushable)).

- -

Note that this is mostly for personal use, so there's no user/authentication control other than that of SSH. Also, most if not all commands here are run as root.

- -

Prerequisites

- -

I might get tired of saying this (it's just copy paste, basically)… but similar as before (check my website and mail entries):

- - +

git server

If not installed already, install the git package:

-
pacman -S git
 
- -

On Arch Linux, when you install the git package, a git user is automatically created, so all you have to do is decide where you want to store the repositories, for me, I like them to be on /home/git like if git was a “normal” user. So, create the git folder (with corresponding permissions) under /home and set the git user's home to /home/git:

- +

On Arch Linux, when you install the git package, a git user is automatically created, so all you have to do is decide where you want to store the repositories, for me, I like them to be on /home/git like if git was a “normal” user. So, create the git folder (with corresponding permissions) under /home and set the git user’s home to /home/git:

mkdir /home/git
 chown git:git /home/git
 usermod -d /home/git git
 
- -

Also, the git user is “expired” by default and will be locked (needs a password), change that with:

- +

Also, the git user is “expired” by default and will be locked (needs a password), change that with:

chage -E -1 git
 passwd git
 
-

Give it a strong one and remember to use PasswordAuthentication no for ssh (as you should). Create the .ssh/authorized_keys for the git user and set the permissions accordingly:

-
mkdir /home/git/.ssh
 chmod 700 /home/git/.ssh
 touch /home/git/.ssh/authorized_keys
 chmod 600 /home/git/.ssh/authorized_keys
 chown -R git:git /home/git
 
- -

Now is a good idea to copy over your local SSH public keys to this file, to be able to push/pull to the repositories. Do it by either manually copying it or using ssh's built in ssh-copy-id (for that you may want to check your ssh configuration in case you don't let people access your server with user/password).

- +

Now is a good idea to copy over your local SSH public keys to this file, to be able to push/pull to the repositories. Do it by either manually copying it or using ssh‘s built in ssh-copy-id (for that you may want to check your ssh configuration in case you don’t let people access your server with user/password).

Next, and almost finally, we need to edit the git-daemon service, located at /usr/lib/systemd/system/ (called git-daemon@.service):

-
...
 ExecStart=-/usr/lib/git-core/git-daemon --inetd --export-all --base-path=/home/git --enable=receive-pack
 ...
 
- -

I just appended --enable=receive-pack and note that I also changed the --base-path to reflect where I want to serve my repositories from (has to match what you set when changing git user's home).

- +

I just appended --enable=receive-pack and note that I also changed the --base-path to reflect where I want to serve my repositories from (has to match what you set when changing git user’s home).

Now, go ahead and start and enable the git-daemon socket:

-
systemctl start git-daemon.socket
 systemctl enable git-daemon.socket
 
- -

You're basically done. Now you should be able to push/pull repositories to your server… except, you haven't created any repository in your server, that's right, they're not created automatically when trying to push. To do so, you have to do the following sequence (assuming you're “cd'ed” into the /home/git directory):

- +

You’re basically done. Now you should be able to push/pull repositories to your server… except, you haven’t created any repository in your server, that’s right, they’re not created automatically when trying to push. To do so, you have to do the following sequence (assuming you’re “cd‘ed” into the /home/git directory):

mkdir {repo_name}.git
 cd {repo_name}.git
 
- -

Those two lines above will need to be run each time you want to add a new repository to your server (yeah, kinda lame… although there are options to “automate” this, I like it this way).

- +

Those two lines above will need to be run each time you want to add a new repository to your server (yeah, kinda lame… although there are options to “automate” this, I like it this way).

After that you can already push/pull to your repository. I have my repositories (locally) set up so I can push to more than one remote at the same time (my server, GitHub, GitLab, etc.), which is detailed here.

- -

cgit

- +

cgit

This bit is optional if you only wanted a git server (really easy to set up), this is so you can have a web application. This is basically a copy paste of Arch Linux Wiki: Cgit so you can go there and get more in-depth configurations.

-

Install the cgit and fcgiwrap packages:

-
pacman -S cgit fcgiwrap
 
-

Now, just start and enable the fcgiwrap socket:

-
systemctl start fcgiwrap.socket
 systemctl enable fcgiwrap.socket
 
-

Next, the way I configure nginx is creating a separate file {module}.conf (git.conf in this case) under /etc/nginx/sites-available and create a symlink to /etc/nginx/sites-enabled as stated in my nginx setup entry. Add the following lines to your git.conf file:

-
server {
     listen 80;
     listen [::]:80;
@@ -176,11 +142,8 @@ systemctl enable fcgiwrap.socket
     }
 }
 
- -

Where the server_name line depends on you, I have mine setup to git.luevano.xyz and www.git.luevano.xyz. Optionally run certbot --nginx to get a certificate for those domains if you don't have already.

- -

Now, all that's left is to configure cgit. Create the configuration file /etc/cgitrc with the following content (my personal options, pretty much the default):

- +

Where the server_name line depends on you, I have mine setup to git.luevano.xyz and www.git.luevano.xyz. Optionally run certbot --nginx to get a certificate for those domains if you don’t have already.

+

Now, all that’s left is to configure cgit. Create the configuration file /etc/cgitrc with the following content (my personal options, pretty much the default):

css=/cgit.css
 source-filter=/usr/lib/cgit/filters/syntax-highlighting-edited.sh
 logo=/cgit.png
@@ -196,9 +159,7 @@ repo.desc={short_description}
 
 ...
 
- -

Where you can uncomment the robots line to let web crawlers (like Google's) to index your git web app. And at the end keep all your repositories (the ones you want to make public), for example for my dotfiles I have:

- +

Where you can uncomment the robots line to let web crawlers (like Google’s) to index your git web app. And at the end keep all your repositories (the ones you want to make public), for example for my dotfiles I have:

...
 repo.url=.dots
 repo.path=/home/git/.dots.git
@@ -206,15 +167,11 @@ repo.owner=luevano
 repo.desc=These are my personal dotfiles.
 ...
 
- -

Otherwise you could let cgit to automatically detect your repositories (you have to be careful if you want to keep “private” repos) using the option scan-path and setup .git/description for each repository. I will add more to my actual configuration, but for now it is useful as it is. For more, you can check cgitrc(5).

- -

Finally, if you want further support for highlighting, other compressed snapshots or support for markdown, checkout the optional dependencies for cgit and also the Arch Wiki goes in detail on how to setup highlighting with two different packages.

- -
-
-

Created: Sat, Mar 20, 2021 @ 22:58 MST; modified: Sun, Mar 21, 2021 @ 12:00 MST

-
+

Otherwise you could let cgit to automatically detect your repositories (you have to be careful if you want to keep “private” repos) using the option scan-path and setup .git/description for each repository. I will add more to my actual configuration, but for now it is useful as it is. For more, you can check cgitrc(5).

+

Finally, if you want further support for highlighting, other compressed snapshots or support for markdown, checkout the optional dependencies for cgit and also the Arch Wiki goes in detail on how to setup highlighting with two different packages.

Tags: +english, git, nginx, tools, tutorial

+

By: David Luévano

+

Created: Sun, 21 Mar, 2021 @ 19:00 UTC, edited: Mon, 17 May, 2021 @ 21:03 UTC

-- cgit v1.2.3-70-g09d2