period3.xyz/content/gemlog/2022/04/05/git-server.gmi

77 lines
1.7 KiB
Plaintext
Raw Normal View History

2022-04-05 02:39:56 +02:00
=> ../../../index.gmi Index
=> https://git-scm.com/ Git [www]
# A minimal Git server
Sometimes hosted services aren't the right fit for the job. Here are some basic steps for setting up and using remote Git repositories on a remote Debian host. You will need sudo access.
## Create a Git User
Add a user to own the repositories:
```
sudo adduser git
```
Start a session for the new user in their home directory:
```
sudo su -l git
```
## Configure SSH access
Create the `.ssh` directory and make it readable only to the new user.
```
mkdir ~/.ssh
chmod 700 ~/.ssh
```
Create an `authorized_keys` file in the `.ssh` directory, and make it accessible only to the new user.
```
touch .ssh/authorized_keys
chmod 600 `.ssh/authorized_keys`
```
Create a public/private key pair locally to authenticate a user when connecting to the remote host.
```
ssh-keygen -t rsa
```
Copy the key into the (remote) git user's `.ssh/authorized_keys`, for example using `ssh-copy-id` or by giving the public key to the server administrator.
Add an entry to your local `.ssh/config`:
```
Host myhost
HostName chaos.period3.xyz
User git
IdentityFile ~/.ssh/id_rsa
```
Test the configuration with:
```
ssh myhost
```
## Create a bare repository
Create directories within the git user's home directory (nested paths are allowed). Conventionally Git repositories use a `.git` suffix, for example `my-projects/my-repo.git` or just `my-repo.git`.
```
git init --bare repo.git
```
There now exists an empty Git repository on the host. The remote can be added to a local repository:
```
git remote add origin git@host:my-repo.git
git push -u origin main
```