···55on the [AT Protocol](https://atproto.com).6677Read the introduction to Tangled [here](https://blog.tangled.sh/intro).88+99+## knot self-hosting guide1010+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 setup2222+2323+First, clone this repository:2424+2525+```2626+git clone https://tangled.sh/@tangled.sh/core2727+```2828+2929+Then, build our binaries (you need to have Go installed):3030+* `knotserver`: the main server program3131+* `keyfetch`: utility to fetch ssh pubkeys3232+* `repoguard`: enforces repository access control3333+3434+```3535+cd core3636+export CGO_ENABLED=13737+go build -o knot ./cmd/knotserver3838+go build -o keyfetch ./cmd/keyfetch3939+go build -o repoguard ./cmd/repoguard4040+```4141+4242+Next, move the `keyfetch` binary to a location owned by `root` -- `/keyfetch` is4343+a good choice:4444+4545+```4646+sudo mv keyfetch /keyfetch4747+sudo chown root:root /keyfetch4848+sudo chmod 755 /keyfetch4949+```5050+5151+This is necessary because SSH `AuthorizedKeysCommand` requires [really specific5252+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 <<EOF5656+Match User git5757+ AuthorizedKeysCommand /keyfetch5858+ AuthorizedKeysCommandUser nobody5959+EOF6060+```6161+6262+Next, create the `git` user:6363+6464+```6565+sudo adduser git6666+```6767+6868+Copy the `repoguard` binary to the `git` user's home directory:6969+7070+```7171+sudo cp repoguard /home/git7272+sudo chown git:git /home/git/repoguard7373+```7474+7575+Now, let's set up the server. Copy the `knot` binary to7676+`/usr/local/bin/knotserver`. Then, create `/home/git/.knot.env` with the7777+following, updating the values as necessary. The `KNOT_SERVER_SECRET` can be7878+obtaind from the [/knots](/knots) page on Tangled.7979+8080+```8181+KNOT_REPO_SCAN_PATH=/home/git8282+KNOT_SERVER_HOSTNAME=knot.example.com8383+APPVIEW_ENDPOINT=https://tangled.sh8484+KNOT_SERVER_SECRET=secret8585+KNOT_SERVER_INTERNAL_LISTEN_ADDR=127.0.0.1:54448686+KNOT_SERVER_LISTEN_ADDR=127.0.0.1:55558787+```8888+8989+If you run a Linux distribution that uses systemd, you can use the provided9090+service file to run the server. Copy9191+[`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 knotserver9696+systemctl start knotserver9797+```9898+9999+You should now have a running knot server! You can finalize your registration by hitting the100100+`initialize` button on the [/knots](/knots) page.