···55on the [AT Protocol](https://atproto.com).
6677Read the introduction to Tangled [here](https://blog.tangled.sh/intro).
88+99+## knot self-hosting guide
1010+1111+So you want to run your own knot server? Great! Here are a few prerequisites:
1212+1313+1. A server of some kind (a VPS, a Raspberry Pi, etc.). Preferably running a Linux of some kind.
1414+2. A (sub)domain name. People generally use `knot.example.com`.
1515+3. A valid SSL certificate for your domain.
1616+1717+There's a couple of ways to get started:
1818+* NixOS: refer to [flake.nix](https://tangled.sh/@tangled.sh/core/blob/master/flake.nix)
1919+* Manual: Documented below.
2020+2121+### manual setup
2222+2323+First, clone this repository:
2424+2525+```
2626+git clone https://tangled.sh/@tangled.sh/core
2727+```
2828+2929+Then, build our binaries (you need to have Go installed):
3030+* `knotserver`: the main server program
3131+* `keyfetch`: utility to fetch ssh pubkeys
3232+* `repoguard`: enforces repository access control
3333+3434+```
3535+cd core
3636+export CGO_ENABLED=1
3737+go build -o knot ./cmd/knotserver
3838+go build -o keyfetch ./cmd/keyfetch
3939+go build -o repoguard ./cmd/repoguard
4040+```
4141+4242+Next, move the `keyfetch` binary to a location owned by `root` -- `/keyfetch` is
4343+a good choice:
4444+4545+```
4646+sudo mv keyfetch /keyfetch
4747+sudo chown root:root /keyfetch
4848+sudo chmod 755 /keyfetch
4949+```
5050+5151+This is necessary because SSH `AuthorizedKeysCommand` requires [really specific
5252+permissions](https://stackoverflow.com/a/27638306). Let's set that up:
5353+5454+```
5555+sudo tee /etc/ssh/sshd_config.d/authorized_keys_command.conf <<EOF
5656+Match User git
5757+ AuthorizedKeysCommand /keyfetch
5858+ AuthorizedKeysCommandUser nobody
5959+EOF
6060+```
6161+6262+Next, create the `git` user:
6363+6464+```
6565+sudo adduser git
6666+```
6767+6868+Copy the `repoguard` binary to the `git` user's home directory:
6969+7070+```
7171+sudo cp repoguard /home/git
7272+sudo chown git:git /home/git/repoguard
7373+```
7474+7575+Now, let's set up the server. Copy the `knot` binary to
7676+`/usr/local/bin/knotserver`. Then, create `/home/git/.knot.env` with the
7777+following, updating the values as necessary. The `KNOT_SERVER_SECRET` can be
7878+obtaind from the [/knots](/knots) page on Tangled.
7979+8080+```
8181+KNOT_REPO_SCAN_PATH=/home/git
8282+KNOT_SERVER_HOSTNAME=knot.example.com
8383+APPVIEW_ENDPOINT=https://tangled.sh
8484+KNOT_SERVER_SECRET=secret
8585+KNOT_SERVER_INTERNAL_LISTEN_ADDR=127.0.0.1:5444
8686+KNOT_SERVER_LISTEN_ADDR=127.0.0.1:5555
8787+```
8888+8989+If you run a Linux distribution that uses systemd, you can use the provided
9090+service file to run the server. Copy
9191+[`knotserver.service`](https://tangled.sh/did:plc:wshs7t2adsemcrrd4snkeqli/core/blob/master/systemd/knotserver.service)
9292+to `/etc/systemd/system/`. Then, run:
9393+9494+```
9595+systemctl enable knotserver
9696+systemctl start knotserver
9797+```
9898+9999+You should now have a running knot server! You can finalize your registration by hitting the
100100+`initialize` button on the [/knots](/knots) page.