···34git clone https://tangled.sh/@tangled.sh/core
35```
3637-Then, build our binaries (you need to have Go installed):
38-* `knotserver`: the main server program
39-* `keyfetch`: utility to fetch ssh pubkeys
40-* `repoguard`: enforces repository access control
000004142```
43cd core
44export CGO_ENABLED=1
45-go build -o knot ./cmd/knotserver
46-go build -o keyfetch ./cmd/keyfetch
47-go build -o repoguard ./cmd/repoguard
48```
4950-Next, move the `keyfetch` binary to a location owned by `root` --
51-`/usr/local/libexec/tangled-keyfetch` is a good choice:
5253```
54-sudo mv keyfetch /usr/local/libexec/tangled-keyfetch
55-sudo chown root:root /usr/local/libexec/tangled-keyfetch
56-sudo chmod 755 /usr/local/libexec/tangled-keyfetch
57```
5859-This is necessary because SSH `AuthorizedKeysCommand` requires [really specific
60-permissions](https://stackoverflow.com/a/27638306). Let's set that up:
0006162```
63sudo tee /etc/ssh/sshd_config.d/authorized_keys_command.conf <<EOF
64Match User git
65- AuthorizedKeysCommand /usr/local/libexec/tangled-keyfetch
66 AuthorizedKeysCommandUser nobody
67EOF
68```
6970-Next, create the `git` user:
07172```
73sudo adduser git
74```
7576-Copy the `repoguard` binary to the `git` user's home directory:
77-78-```
79-sudo cp repoguard /home/git
80-sudo chown git:git /home/git/repoguard
81-```
82-83-Now, let's set up the server. Copy the `knot` binary to
84-`/usr/local/bin/knotserver`. Then, create `/home/git/.knot.env` with the
85-following, updating the values as necessary. The `KNOT_SERVER_SECRET` can be
86-obtaind from the [/knots](/knots) page on Tangled.
8788```
89KNOT_REPO_SCAN_PATH=/home/git
···9697If you run a Linux distribution that uses systemd, you can use the provided
98service file to run the server. Copy
99-[`knotserver.service`](https://tangled.sh/did:plc:wshs7t2adsemcrrd4snkeqli/core/blob/master/systemd/knotserver.service)
100to `/etc/systemd/system/`. Then, run:
101102```
···161KNOT_REPO_SCAN_PATH=/home/git/repositories
162```
163164-In your SSH config (e.g. `/etc/ssh/sshd_config.d/authorized_keys_command.conf`),
165-update the `AuthorizedKeysCommand` line to use the new folder. For example:
166167```
0168Match User git
169- AuthorizedKeysCommand /usr/local/libexec/tangled-keyfetch -git-dir /home/git/repositories
170 AuthorizedKeysCommandUser nobody
171-```
172-173-Make sure to restart your SSH server!
174-175-#### git
176-177-The keyfetch executable takes multiple arguments to change certain paths. You
178-can view a full list by running `/usr/local/libexec/tangled-keyfetch -h`.
179-180-As an example, if you wanted to change the path to the repoguard executable,
181-you would edit your SSH config (e.g. `/etc/ssh/sshd_config.d/authorized_keys_command.conf`)
182-and update the `AuthorizedKeysCommand` line:
183-184-```
185-Match User git
186- AuthorizedKeysCommand /usr/local/libexec/tangled-keyfetch -repoguard-path /path/to/repoguard
187- AuthorizedKeysCommandUser nobody
188```
189190Make sure to restart your SSH server!
···34git clone https://tangled.sh/@tangled.sh/core
35```
3637+Then, build the `knot` CLI. This is the knot administration and operation tool.
38+For the purpose of this guide, we're only concerned with these subcommands:
39+40+* `knot server`: the main knot server process, typically run as a
41+supervised service
42+* `knot guard`: handles role-based access control for git over SSH
43+(you'll never have to run this yourself)
44+* `knot keys`: fetches SSH keys associated with your knot; we'll use
45+this to generate the SSH `AuthorizedKeysCommand`
4647```
48cd core
49export CGO_ENABLED=1
50+go build -o knot ./cmd/knot
0051```
5253+Next, move the `knot` binary to a location owned by `root` --
54+`/usr/local/bin/knot` is a good choice:
5556```
57+sudo mv knot /usr/local/bin/knot
0058```
5960+This is necessary because SSH `AuthorizedKeysCommand` requires [really
61+specific permissions](https://stackoverflow.com/a/27638306). The
62+`AuthorizedKeysCommand` specifies a command that is run by `sshd` to
63+retrieve a user's public SSH keys dynamically for authentication. Let's
64+set that up.
6566```
67sudo tee /etc/ssh/sshd_config.d/authorized_keys_command.conf <<EOF
68Match User git
69+ AuthorizedKeysCommand /usr/local/bin/knot keys -o authorized-keys
70 AuthorizedKeysCommandUser nobody
71EOF
72```
7374+Next, create the `git` user. We'll use the `git` user's home directory
75+to store repositories:
7677```
78sudo adduser git
79```
8081+Create `/home/git/.knot.env` with the following, updating the values as
82+necessary. The `KNOT_SERVER_SECRET` can be obtaind from the
83+[/knots](/knots) page on Tangled.
000000008485```
86KNOT_REPO_SCAN_PATH=/home/git
···9394If you run a Linux distribution that uses systemd, you can use the provided
95service file to run the server. Copy
96+[`knotserver.service`](/systemd/knotserver.service)
97to `/etc/systemd/system/`. Then, run:
9899```
···158KNOT_REPO_SCAN_PATH=/home/git/repositories
159```
160161+Similarly, update your `sshd` `AuthorizedKeysCommand` to use the updated
162+repository path:
163164```
165+sudo tee /etc/ssh/sshd_config.d/authorized_keys_command.conf <<EOF
166Match User git
167+ AuthorizedKeysCommand /usr/local/bin/knot keys -o authorized-keys -git-dir /home/git/repositories
168 AuthorizedKeysCommandUser nobody
169+EOF
0000000000000000170```
171172Make sure to restart your SSH server!