Git server

Ported from old, incomplete Ubuntu installation tutorial, in an attempt to clean up some pages. This was from 2021-06-27.

Usage of some intermediate commands in Git is found here. This article is more about setting up the Git server.

Setup Git server

Based on the official documentation.

$ sudo adduser git   # set a password
$ su git
$ mkdir ~/.ssh && chmod 700 ~/.ssh
# touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys

Copy the public key of each user to the authorized_keys file for the git user.

$ cat /tmp/id_rsa.user.pub >> ~/.ssh/authorized_keys

Restrict the shell of the git user to a more restricted git-shell, i.e. user cannot shell into the machine.

$ which git-shell        # identifies location of git-shell
/usr/bin/git-shell
$ sudo vim /etc/shells   # manually add path to 'git-shell'
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/usr/bin/tmux
/usr/bin/screen
/usr/bin/git-shell
$ sudo chsh git -s $(which git-shell)

Restrict access via SSH port forwarding as well by prepending to each key in authorized_keys the options no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty, in other words the file will look like this:

$ sudo cat /home/git/.ssh/authorized_keys
no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCotgBM2PfB4D2F+TpSdsDJ6Z57X2e1iCmMdVup2EWP7PMuf0/HkeICqboQYS[REDACTED]

Continue the tutorial here...