1 0111ad5d 2021-10-09 op <!doctype html>
2 0111ad5d 2021-10-09 op <html lang="en">
4 35340c9f 2021-10-09 op <title>gmid quickstart</title>
5 0111ad5d 2021-10-09 op <meta charset="utf8" />
6 0111ad5d 2021-10-09 op <meta name="viewport" content="width=device-width, initial-scale=1" />
9 0111ad5d 2021-10-09 op font-family: monospace;
10 0111ad5d 2021-10-09 op font-size: 14px;
11 0111ad5d 2021-10-09 op max-width: 780px;
12 0111ad5d 2021-10-09 op margin: 0 auto;
13 0111ad5d 2021-10-09 op padding: 20px;
14 0111ad5d 2021-10-09 op padding-bottom: 80px;
18 0111ad5d 2021-10-09 op content: "# ";
22 0111ad5d 2021-10-09 op margin-top: 40px;
26 0111ad5d 2021-10-09 op content: "## ";
30 0111ad5d 2021-10-09 op content: "### ";
38 0111ad5d 2021-10-09 op blockquote::before {
39 0111ad5d 2021-10-09 op content: "> ";
42 0111ad5d 2021-10-09 op blockquote p {
43 0111ad5d 2021-10-09 op font-style: italic;
44 0111ad5d 2021-10-09 op display: inline;
47 0111ad5d 2021-10-09 op p.link::before {
48 0111ad5d 2021-10-09 op content: "→ ";
51 0111ad5d 2021-10-09 op strong::before { content: "*" }
52 0111ad5d 2021-10-09 op strong::after { content: "*" }
57 0111ad5d 2021-10-09 op background-color: #222;
59 0111ad5d 2021-10-09 op display: block;
60 0111ad5d 2021-10-09 op margin: 2em auto;
64 0111ad5d 2021-10-09 op border-radius: 5px;
68 0111ad5d 2021-10-09 op overflow: auto;
69 0111ad5d 2021-10-09 op padding: 1rem;
70 0111ad5d 2021-10-09 op background-color: #f0f0f0;
71 0111ad5d 2021-10-09 op border-radius: 3px;
75 0111ad5d 2021-10-09 op display: flex;
76 0111ad5d 2021-10-09 op flex-direction: row;
77 0111ad5d 2021-10-09 op justify-content: center;
81 0111ad5d 2021-10-09 op color: #9d109d;
85 0111ad5d 2021-10-09 op display: block;
86 0111ad5d 2021-10-09 op margin: 0 auto;
87 0111ad5d 2021-10-09 op max-width: 100%;
90 0111ad5d 2021-10-09 op @media (prefers-color-scheme: dark) {
92 0111ad5d 2021-10-09 op background-color: #222;
101 0111ad5d 2021-10-09 op background-color: #ddd;
105 0111ad5d 2021-10-09 op background-color: #353535;
109 0111ad5d 2021-10-09 op color: #ff4cff;
113 0111ad5d 2021-10-09 op @media (max-width: 400px) {
114 0111ad5d 2021-10-09 op pre.banner { font-size: 9px; }
117 0111ad5d 2021-10-09 op @media (max-width: 500px) {
118 0111ad5d 2021-10-09 op pre.banner { font-size: 10px; }
125 0111ad5d 2021-10-09 op <a href="/">Home</a> |
126 0111ad5d 2021-10-09 op <a href="contrib.html">contrib</a> |
128 0111ad5d 2021-10-09 op <a href="gmid.1.html">docs</a>
131 0111ad5d 2021-10-09 op <h1>gmid quickstart</h1>
132 0111ad5d 2021-10-09 op <p>gmid can be run in two different “modes”:</p>
134 0111ad5d 2021-10-09 op <dt>configless:</dt>
136 0111ad5d 2021-10-09 op a quick way to serve a directory tree from the shell, useful
137 0111ad5d 2021-10-09 op for testing a capsule before uploading it
139 0111ad5d 2021-10-09 op <dt>daemon mode:</dt>
141 0111ad5d 2021-10-09 op gmid reads the configuration file and runs in the background
144 0111ad5d 2021-10-09 op <p>To run gmid in the “configless” mode, just type:</p>
145 0111ad5d 2021-10-09 op <pre>$ gmid path/to/dir</pre>
147 0111ad5d 2021-10-09 op gmid will then generate a certificate inside ~/.local/share/gmid
148 540d05de 2021-10-09 op and serve the given directory locally.
150 fc4b58d4 2021-10-11 op <h2>Setting up a capsule with gmid</h2>
151 fc4b58d4 2021-10-11 op <p>To host a Gemini capsule you need to run gmid in “daemon” mode.</p>
153 0111ad5d 2021-10-09 op To run gmid in daemon mode a configuration file is needed. The
154 0111ad5d 2021-10-09 op format of the configuration file is described in the manpage and
155 fc4b58d4 2021-10-11 op is quite flexible, but something like the following should be
156 fc4b58d4 2021-10-11 op enough to start:
158 0111ad5d 2021-10-09 op <pre># /etc/gmid.conf
160 0111ad5d 2021-10-09 op server "example.com" {
161 0111ad5d 2021-10-09 op cert "/path/to/certificate"
162 0111ad5d 2021-10-09 op key "/path/to/private-key"
163 0111ad5d 2021-10-09 op root "/var/gemini/example.com"
166 fc4b58d4 2021-10-11 op You also need to generate a certificate for the capsule. A
167 fc4b58d4 2021-10-11 op X.509 (TLS) certificate can be generated for e.g. with
168 0111ad5d 2021-10-09 op <a href="https://git.omarpolo.com/gmid/tree/contrib/gencert">contrib/gencert</a>:
170 0111ad5d 2021-10-09 op <pre>$ ./contrib/gencert example.com
171 0111ad5d 2021-10-09 op Generating a 4096 bit RSA private key
172 0111ad5d 2021-10-09 op .................................................++++
173 0111ad5d 2021-10-09 op ..........++++
174 0111ad5d 2021-10-09 op writing new private key to './example.com.key'
177 0111ad5d 2021-10-09 op Generated files:
178 0111ad5d 2021-10-09 op ./example.com.pem : certificate
179 0111ad5d 2021-10-09 op ./example.com.key : private key</pre>
181 35340c9f 2021-10-09 op Optionally, move ‘example.com.pem’ and ‘example.com.key’ to
182 0111ad5d 2021-10-09 op another location.
185 0111ad5d 2021-10-09 op Make sure that the ‘cert’ and ‘key’ options in the configuration
186 0111ad5d 2021-10-09 op file points to these files.
188 0111ad5d 2021-10-09 op <p>Then running gmid is as easy as</p>
189 0111ad5d 2021-10-09 op <pre>$ gmid -c /etc/gmid.conf</pre>
190 fc4b58d4 2021-10-11 op <p>Congratulations, your capsule is online!</p>
191 0111ad5d 2021-10-09 op <h2>Securing your gmid installation</h2>
193 0111ad5d 2021-10-09 op gmid employs various techniques to prevent the damage caused by
194 0111ad5d 2021-10-09 op bugs, but some steps needs to be done manually.
197 0111ad5d 2021-10-09 op If gmid was installed from your distribution package manager,
198 0111ad5d 2021-10-09 op chance are that it already does all of this and is also
199 0111ad5d 2021-10-09 op providing a service to run gmid automatically (e.g. a systemd
200 0111ad5d 2021-10-09 op unit file, a rc script, …) Otherwise, it’s heavily suggested to
201 0111ad5d 2021-10-09 op create at least a dedicated user.
203 0111ad5d 2021-10-09 op <h3>A dedicated user</h3>
205 fc4b58d4 2021-10-11 op Ideally, gmid should be started as root and drop privileges to a
206 fc4b58d4 2021-10-11 op local user. This way, the certificates can be readable only by
207 fc4b58d4 2021-10-11 op root. For example, on GNU/linux systems a ‘gmid’ user can be
208 fc4b58d4 2021-10-11 op created with:
210 35340c9f 2021-10-09 op <pre># useradd --system --no-create-home -s /bin/nologin -c "gmid Gemini server" gmid</pre>
212 0111ad5d 2021-10-09 op Please consult your OS documentation for more information on the
216 0111ad5d 2021-10-09 op The configuration then needs to be adjusted to include the
217 0111ad5d 2021-10-09 op ‘user’ directive at the top:
219 0111ad5d 2021-10-09 op <pre># /etc/gmid.conf
222 0111ad5d 2021-10-09 op server "example.com" { … }</pre>
224 0111ad5d 2021-10-09 op gmid then needs to be started with root privileges, but will
225 0111ad5d 2021-10-09 op then switch to the provided user automatically. If by accident
226 fc4b58d4 2021-10-11 op the ‘user’ option is omitted and gmid is running as root, it
227 fc4b58d4 2021-10-11 op will complain loudly in the logs.
229 0111ad5d 2021-10-09 op <h3>chroot</h3>
231 0111ad5d 2021-10-09 op It’s a common practice for system daemons to chroot themselves
232 0111ad5d 2021-10-09 op into a directory. From here on I’ll assume /var/gemini, but it
233 0111ad5d 2021-10-09 op can be any directory.
236 0111ad5d 2021-10-09 op A chroot on UNIX-like OS is an operation that changes the
237 fc4b58d4 2021-10-11 op “apparent” root directory (i.e. the “/”) from the current
238 fc4b58d4 2021-10-11 op process and its child. Think of it like imprisoning a process
239 fc4b58d4 2021-10-11 op into a directory and never letting it escape until it
243 0111ad5d 2021-10-09 op Using a chroot may complicate the use of CGI scripts, because
244 fc4b58d4 2021-10-11 op then all the dependencies of the scripts (sh, perl, libraries…)
245 fc4b58d4 2021-10-11 op need to be installed inside the chroot too. For this very
246 fc4b58d4 2021-10-11 op reason gmid supports FastCGI.
249 0111ad5d 2021-10-09 op The chroot feature requires a dedicate user, see the previous
253 0111ad5d 2021-10-09 op To chroot gmid inside a directory, use the ‘chroot’ directive in
254 0111ad5d 2021-10-09 op the configuration file:
256 0111ad5d 2021-10-09 op <pre># /etc/gmid.conf
260 0111ad5d 2021-10-09 op # the given directory, /var/gemini in this case, must exists.
261 0111ad5d 2021-10-09 op chroot "/var/gemini"</pre>
263 0111ad5d 2021-10-09 op Note that once ‘chroot’ is in place, every ‘root’ directive is
264 0111ad5d 2021-10-09 op implicitly relative to the chroot, but ‘cert’ and ‘key’ aren’t!
266 0111ad5d 2021-10-09 op <p>For example, given the following configuration:</p>
267 0111ad5d 2021-10-09 op <pre># /etc/gmid.conf
270 0111ad5d 2021-10-09 op chroot "/var/gemini"
272 0111ad5d 2021-10-09 op server "example.com" {
273 0111ad5d 2021-10-09 op cert "/etc/ssl/example.com.pem"
274 0111ad5d 2021-10-09 op key "/etc/ssl/example.com.key"
275 0111ad5d 2021-10-09 op root "/example.com"
278 0111ad5d 2021-10-09 op The certificate and the key path are the specified ones, but the
279 0111ad5d 2021-10-09 op root directory of the virtual host is actually
280 0111ad5d 2021-10-09 op “/var/gemini/example.com/”.