Little bit of polish

This commit is contained in:
Nox Sluijtman 2022-09-30 16:04:11 +02:00
parent c5df08a72c
commit eb72c5fc46

View file

@ -3,7 +3,7 @@ title: 'Hosting your own Git "server"'
date: "2022-09-30T14:27:31+02:00" date: "2022-09-30T14:27:31+02:00"
author: "$HUMANOID" author: "$HUMANOID"
tags: ["git", "ssh"] tags: ["git", "ssh"]
description: "The basis of a Git server is a machine accessible in a way that git understands with a bunch of bare git repositories" description: "The basis of a Git server is a machine accessible in a way that Git understands with a bunch of bare repositories"
toc: true toc: true
--- ---
@ -51,7 +51,7 @@ ssh-keygen -t ed25519 -f ~/.ssh/<git-key>
``` ```
I also recommend creating an entry in `~/.ssh/config` for your Git server: I also recommend creating an entry in `~/.ssh/config` for your Git server:
```ssh_config ```ssh_config
Host <host> Host <host>-git
Hostname <hostname> Hostname <hostname>
User git User git
Identityfile ~/.ssh/<git-key> Identityfile ~/.ssh/<git-key>
@ -59,7 +59,8 @@ Host <host>
### Server side ### Server side
Next step is to make the `git` account accessible over SSH. Next step is to make the `git` account accessible over SSH.
To do this, log in as the `git` user and create a `.ssh` directory with an `authorized_keys` file with the public half of the `<git-key>` keypair: `ssh-copy-id` won't work because the `git` user doesn't have a password.
So instead, log in as the `git` user and create a `.ssh` directory with an `authorized_keys` file with the public half of the `<git-key>` keypair:
```sh ```sh
sudo su - git sudo su - git
umask 077 # strict read write permissions umask 077 # strict read write permissions
@ -83,13 +84,13 @@ That's it.
You now have a Git "server" with a repo named `<repo-name>`. You now have a Git "server" with a repo named `<repo-name>`.
To add something to this repo, on your client machine create a new repository and add `<host>:/srv/git/<repo-name>.git` as remote and push your project to it. To add something to this repo, on your client machine create a new repository and add `<host>-git:/srv/git/<repo-name>.git` as remote and push your project to it.
Common practice dictates that this remote be called `origin`: Common practice dictates that this remote be called `origin`:
```sh ```sh
mkdir my-fancy-project mkdir my-fancy-project
cd my-fancy-project cd my-fancy-project
git init git init
git remote add origin <host>:/srv/git/<repo-name>.git git remote add origin <host>-git:/srv/git/<repo-name>.git
echo "# Self-hosted repo!" > README.md echo "# Self-hosted repo!" > README.md
git add -A git add -A
git commit -m "Initial commit" git commit -m "Initial commit"
@ -98,7 +99,7 @@ git push -u origin main # assuming you use main as your default branch name
To clone this repository on another machine, add the `<git-key>` SSH keypair and related configuration section in `~/.ssh/config` so said machine and run: To clone this repository on another machine, add the `<git-key>` SSH keypair and related configuration section in `~/.ssh/config` so said machine and run:
```sh ```sh
git clone <host>:/srv/git/<repo-name>.git git clone <host>-git:/srv/git/<repo-name>.git
``` ```
# Automation # Automation