<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:exsl="http://exslt.org/common" xml:lang="en">
  <id>https://mallory.computer/feed.xml</id>
  <author>
    <name>Mallory</name>
  </author>
  <updated>2026-04-18T00:00:00Z</updated>
  <link rel="self" href="https://mallory.computer/feed.xml" type="application/atom+xml"/>
  <link href="https://mallory.computer/" type="text/html"/>
  <title>mallory.computer</title>
  <entry>
    <id>https://mallory.computer/posts/2021/05/11/howto-img-freebsd.xml</id>
    <link href="/posts/2021/05/11/howto-img-freebsd.html"/>
    <title>HOWTO: Write a Disk Image to USB Media on FreeBSD</title>
    <published>2021-05-11T00:00:00Z</published>
    <updated>2021-05-11T00:00:00Z</updated>
    <atom:content xmlns="http://www.w3.org/1999/xhtml" type="xhtml">
      <div>
        <p>This HOWTO will describe the process of writing a disk image to USB media using only tools available in all FreeBSD installations. I wrote this using FreeBSD 13.0 but the command line tools and options should work on older versions.</p>
        <p>A disk image will usually end with <code data-nocopy="true">.img</code> or <code data-nocopy="true">.iso</code>. A <code data-nocopy="true">.iso</code> can usually either be written to USB media or to a CD/DVD.</p>
        <p>This document will assume the reader has a very basic understanding of the command line.</p>
        <h1 id="steps">Steps</h1>
        <ol>
          <li>Insert the USB drive into the USB port. If using other media, insert the media into the reader/writer and insert that into the USB port.</li>
          <li>
            <p>Open a terminal and run <code>geom disk list</code> to view all attached disks. You should be able to identify it by the size of the disk (&#x201C;mediasize&#x201D;) and the manufacturer&#x2019;s name (&#x201C;descr&#x201D;).</p>
            <p>Sample output of <code>geom disk list</code>:</p>
            <pre data-nocopy="true">Geom name: da0
Providers:
1. Name: da0
   Mediasize: 8166703104 (7.6G)
   Sectorsize: 512
   Mode: r0w0e0
   descr: Verbatim micro USB
   ident: 11122488000854
   rotationrate: unknown
   fwsectors: 63
   fwheads: 255</pre>
            <p>The name is what we need. Here that&#x2019;s <code data-nocopy="true">da0</code>, but for the remainder of this document I&#x2019;ll refer to it as <code data-nocopy="true"><em>XXX</em></code> to prevent copy/paste accidents.</p>
          </li>
          <li>Run <code>su</code> to switch to root.</li>
          <li>
            <p>Run the following command.</p>
            <div class="warning">
              <h2>WARNING</h2>
              <p>This command is destructive. The disk&#x2019;s data will be entirely overwritten and it will be impossible to retrieve. Only proceed if you&#x2019;re sure you&#x2019;re using the correct disk.</p>
            </div>
            <pre>cat myfile.img /dev/zero | dd of=/dev/<em>XXX</em> bs=1M</pre>
            <p>This command will write <code data-nocopy="true">myfile.img</code> to the <code data-nocopy="true"><em>XXX</em></code> disk, and then continue to write zeros to the disk until the disk is full.</p>
          </li>
        </ol>
        <h1 id="notes">Notes</h1>
        <p>It&#x2019;s important to write zeros to the remainder of the disk as sometimes old data can be interpreted as part of the disk image.</p>
        <p>The <code data-nocopy="true">bs=1M</code> flag is necessary because writing a disk byte-by-byte is extremely slow. Writing a disk in 1 mebibyte blocks (1MiB = 1 mebibyte = 1024&#xB2; bytes) will be significantly faster in most cases. The ideal block size flag to pass will differ depending on the hardware used, but <code data-nocopy="true">1M</code> will work well enough. (<a href="https://serverfault.com/questions/650086/does-the-bs-option-in-dd-really-improve-the-speed">More about the <code data-nocopy="true">bs</code> flag</a>)</p>
      </div>
    </atom:content>
  </entry>
  <entry>
    <id>https://mallory.computer/posts/2023/11/10/transmission-nginx-letsencrypt-wireguard-pf.xml</id>
    <link href="/posts/2023/11/10/transmission-nginx-letsencrypt-wireguard-pf.html"/>
    <title>HOWTO: Install Transmission on FreeBSD 14.0</title>
    <published>2023-11-10T00:00:00Z</published>
    <updated>2025-07-05T00:00:00Z</updated>
    <atom:content xmlns="http://www.w3.org/1999/xhtml" type="xhtml">
      <div>
        <p>In this HOWTO we'll install Transmission on a Raspberry Pi. We'll run Transmission behind nginx which will have a TLS certificate provided by certbot/Let's Encrypt. Transmission will communicate with the internet through a WireGuard VPN, and Transmission will not be allowed to leak when the VPN goes down thanks to PF. In order to grant a TLS certificate to the server we'll need a domain name and the host will need an IPv6 <abbr title="Globally Unique Address">GUA</abbr>.</p>
        <h2>Setting up the Raspberry Pi</h2>
        <ul>
          <li>Set up a domain or subdomain to point at your Raspberry Pi's globally routable IPv6 address (we'll use <code data-nocopy="true"><em>example.invalid</em></code> in this HOWTO)</li>
          <li>Set up your router's firewall to pass in TCP packets on port 80 bound for your Raspberry Pi's IPv6 address (port 80 will only be used to redirect to HTTPS and to renew certificates, so it will be safe to leave open)</li>
          <li>Burn FreeBSD 14.0 to MicroSD card, insert into the Raspberry Pi, attach ethernet and power (<a href="/posts/2021/05/11/howto-img-freebsd.html">guide to burning media on FreeBSD</a>)</li>
          <li><code>ssh-copy-id freebsd@<em>example.invalid</em></code> (the password is <code>freebsd</code>)</li>
          <li>
            <code>scp <em>my-wireguard-config.conf</em> freebsd@<em>example.invalid</em></code>
          </li>
          <li>
            <code>ssh freebsd@<em>example.invalid</em></code>
            <ul>
              <li><code>passwd</code> (change your password to something other than <code data-nocopy="true">freebsd</code>)</li>
              <li><code>su</code> (the password is <code>root</code>)</li>
              <li>
                <code>mkdir -p /usr/local/etc</code>
              </li>
              <li>
                <code>echo permit nopass :wheel &gt; /usr/local/etc/doas.conf</code>
              </li>
              <li>
                <code>pkg install -y doas</code>
              </li>
            </ul>
          </li>
        </ul>
        <h2>Basic setup</h2>
        <p>From now, all commands will assume you're logged into the Pi as user <code data-nocopy="true">freebsd</code>.</p>
        <ul>
          <li>
            <code>doas pkg install -y ca_root_nss</code>
          </li>
          <li>
            <code>doas sysrc hostname=<em>hostname</em></code>
          </li>
          <li>
            <code>doas sysrc ntpd_enable=YES ntpd_sync_on_start=YES</code>
          </li>
          <li>
            <code>echo 'name_servers="2620:fe::fe 9.9.9.10"' | doas tee /etc/resolvconf.conf</code>
          </li>
          <li>
            <code>echo UseDNS no | doas tee -a /etc/ssh/sshd_config</code>
          </li>
          <li>
            <code>doas mkdir -p /store/www /store/downloads</code>
          </li>
          <li>
            <code>ln -s /store/downloads</code>
          </li>
        </ul>
        <h2>Set up nginx &amp; Let's Encrypt</h2>
        <ul>
          <li>
            <code>doas pkg install -y nginx py39-certbot-nginx</code>
          </li>
          <li>
            <code>doas sysrc nginx_enable=YES</code>
          </li>
          <li>
            <code>doas sysrc -f /etc/periodic.conf weekly_certbot_enable=YES weekly_certbot_service=wireguard</code>
          </li>
          <li>
            <pre>cat &lt;&lt;EOF | doas tee /store/www/index.html
&lt;title&gt;<em>example.invalid</em>&lt;/title&gt;
&lt;link rel="icon" href="/transmission/web/images/favicon.png"&gt;
&lt;h1&gt;<em>example.invalid</em>&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="/transmission/web/"&gt;Transmission&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/downloads/"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
EOF</pre>
          </li>
          <li>
            <pre>cat &lt;&lt;EOF | doas tee /usr/local/etc/nginx/nginx.conf
worker_processes  1;
events {
  worker_connections  1024;
}
http {
  include mime.types;
  default_type application/octet-stream;
  sendfile on;
  keepalive_timeout 65;
  gzip on;
  server {
    listen [::]:80;
    server_name <em>example.invalid</em>;
    location / {
      alias /store/www/;
      index index.html;
    }
    location /downloads/ {
      alias /store/downloads/;
      autoindex on;
      autoindex_exact_size off;
    }
    location /transmission/ {
      proxy_pass http://127.0.0.1:9091;
    }
  }
}
EOF</pre>
          </li>
          <li><code>doas certbot --nginx -d <em>example.invalid</em> --email=<em>your-email@example.invalid</em> --agree-tos --no-eff-email</code><br/>
			You should see the following message:
			<pre data-nocopy="true">Deploying certificate
Successfully deployed certificate for <em>example.invalid</em> to /usr/local/etc/nginx/nginx.conf
Congratulations! You have successfully enabled HTTPS on https://<em>example.invalid</em></pre>
			If you don't you should stop to investigate.
		</li>
        </ul>
        <h2>Set up Transmission</h2>
        <ul>
          <li>
            <code>doas pkg install -y transmission-daemon</code>
          </li>
          <li>
            <code>doas chown transmission:transmission /store/downloads</code>
          </li>
          <li>
            <code>doas sysrc transmission_download_dir=/store/downloads transmission_enable=YES</code>
          </li>
        </ul>
        <h2>Set up WireGuard</h2>
        <ul>
          <li>
            <code>doas pkg install -y wireguard-tools</code>
          </li>
          <li>
            <code>doas cp <em>my-wireguard-config.conf</em> /usr/local/etc/wireguard/wg0.conf</code>
          </li>
          <li>
            <code>doas sysrc wireguard_interfaces=wg0 wireguard_enable=YES</code>
          </li>
          <li>
            <code>doas service wireguard start</code>
          </li>
          <li>Test that your IP addresses have changed: <code>fetch --quiet --output=- http://ip6only.me/api/ &amp;&amp; fetch --quiet --output=- http://ip4only.me/api/</code></li>
        </ul>
        <h2>Set up PF</h2>
        <ul>
          <li>
            <pre>cat &lt;&lt;EOF | doas tee /etc/pf.conf
set skip on lo0

# Block all incoming connections from wg0
block in on wg0

# Prevent leaks from Transmission
block user transmission
pass on wg0 user transmission

# But allow other users to do anything
pass user != transmission
EOF</pre>
          </li>
        </ul>
        <p>Let's test that pf works correctly:</p>
        <ul>
          <li>
            <code>doas service pf onestart</code>
          </li>
          <li>If pf prevents you interacting over ssh, reboot it by pulling out unplugging the power cable and plugging it back in again.</li>
          <li>
            <code>doas service wireguard stop</code>
          </li>
          <li>
            <code>doas -u transmission fetch --quiet --output=- http://ip6only.me/api/ ; doas -u transmission fetch --quiet --output=- http://ip4only.me/api/</code>
          </li>
          <li>You should see <samp data-nocopy="true">Host does not resolve</samp> twice.</li>
          <li>
            <code>doas service wireguard start</code>
          </li>
          <li>
            <code>doas -u transmission fetch --quiet --output=- http://ip6only.me/api/ ; doas -u transmission fetch --quiet --output=- http://ip4only.me/api/</code>
          </li>
          <li>You should see the VPN's IP addresses.</li>
        </ul>
        <p>Once you're satisfied that it's working correctly (and you've verified that you're not being blocked from sshing in), we can enable pf on boot:</p>
        <ul>
          <li>
            <code>doas sysrc pf_enable=YES</code>
          </li>
        </ul>
        <h2>Login info &amp; shell scripts</h2>
        <ul>
          <li>
            <code>echo 'Welcome to <em>hostname</em>!' | doas tee /etc/motd.template</code>
          </li>
          <li>
            <code>echo uptime &gt; .login</code>
          </li>
          <li>
            <pre>cat &lt;&lt;EOF | tee test.sh
#!/bin/sh
set -e

whoami
fetch --quiet --output=- http://ip6only.me/api/ | cut -d, -f2
fetch --quiet --output=- http://ip4only.me/api/ | cut -d, -f2

doas -u transmission whoami
doas -u transmission fetch --quiet --output=- http://ip6only.me/api/ | cut -d, -f2
doas -u transmission fetch --quiet --output=- http://ip4only.me/api/ | cut -d, -f2
EOF</pre>
          </li>
          <li>
            <code>chmod 755 test.sh</code>
          </li>
        </ul>
        <h2>Reboot &amp; done</h2>
        <ul>
          <li>
            <code>doas reboot</code>
          </li>
          <li>Visit <code>https://<em>example.invalid</em>/</code> to see your server with links to Transmission and the downloads directory.</li>
        </ul>
        <p>Now you're ready to download your favorite BSD without every other BitTorrent peer knowing your IP address!</p>
        <p>
          <img alt="Transmission's web interface showing FreeBSD 13.2 seeding" src="transmission-freebsd.png"/>
        </p>
        <h2>Errata</h2>
        <p>When the Let's Encrypt certificate expires, it will not be renewed automatically due to a quirk of the routing that gets set up. This can be fixed by commenting-out a couple of lines.</p>
        <ul>
          <li>
            <code>doas vi /usr/local/bin/wg-quick</code>
          </li>
          <li>
				Comment-out the following lines:<br/>
				<pre>cmd route -q -n add -inet6 ::/1 -interface "$INTERFACE"
cmd route -q -n add -inet6 8000::/1 -interface "$INTERFACE"</pre>
		</li>
        </ul>
      </div>
    </atom:content>
  </entry>
  <entry>
    <id>https://mallory.computer/posts/2025/01/07/howto-freebsd-windows-disk.html</id>
    <link href="/posts/2025/01/07/howto-freebsd-windows-disk.html"/>
    <title>HOWTO: Create a Windows-readable disk with FreeBSD</title>
    <published>2025-01-07T00:00:00Z</published>
    <updated>2026-01-25T00:00:00Z</updated>
    <atom:content xmlns="http://www.w3.org/1999/xhtml" type="xhtml">
      <div>
        <p>This HOWTO will describe the process of using FreeBSD to format a disk with the FAT32 filesystem so that it can be read by Windows and macOS.</p>
        <h1 id="steps">Steps</h1>
        <ol>
          <li>
            <p>Open a terminal and run <code>geom disk list</code> to view all attached disks. You should be able to identify it by the size of the disk (&#x201C;mediasize&#x201D;) and the manufacturer&#x2019;s name (&#x201C;descr&#x201D;).</p>
            <p>Sample output of <code>geom disk list</code>:</p>
            <pre data-nocopy="true">Geom name: da0
Providers:
1. Name: da0
Mediasize: 8166703104 (7.6G)
Sectorsize: 512
Mode: r0w0e0
descr: Verbatim micro USB
ident: 11122488000854
rotationrate: unknown
fwsectors: 63
fwheads: 255</pre>
            <p>The name is what we need. Here that&#x2019;s <code data-nocopy="true">da0</code>, but for the remainder of this document I&#x2019;ll refer to it as <code data-nocopy="true"><em>XXX</em></code> to prevent copy/paste accidents.</p>
          </li>
          <li>Run <code>su</code> to switch to root.</li>
          <li>
            <p>As root, run the following commands.</p>
            <div class="warning">
              <h2>WARNING</h2>
              <p>The following commands are destructive. The disk&#x2019;s existing data will be overwritten and will become impossible to retrieve. Only proceed if you&#x2019;re sure you&#x2019;re using the correct disk.</p>
            </div>
            <ol>
              <li>
                <p>Destroy the existing partition scheme (if any).</p>
                <pre>gpart destroy -F <em>XXX</em></pre>
              </li>
              <li>
                <p>Create a new <abbr title="Master Boot Record">MBR</abbr> partition scheme.</p>
                <pre>gpart create -s MBR <em>XXX</em></pre>
              </li>
              <li>
                <p>Create a FAT32 (LBA) partition.</p>
                <pre>gpart add -t fat32lba <em>XXX</em></pre>
              </li>
              <li>
                <p>Write a filesystem to the partition we just created.</p>
                <pre>newfs_msdos <em>XXX</em>s1</pre>
              </li>
              <li>
                <pre>mount -t msdos /dev/<em>XXX</em>s1 /mnt</pre>
              </li>
              <li>Put some files on <code data-nocopy="true">/mnt</code>.</li>
              <li>
                <pre>umount /mnt</pre>
              </li>
              <li>It is now safe to remove the disk.</li>
            </ol>
          </li>
        </ol>
        <h1 id="notes">Notes</h1>
        <p><code data-nocopy="true">gpart</code> supports two FAT32 partition types: <code data-nocopy="true">fat32</code> and <code data-nocopy="true">fat32lba</code> (also known as <code data-nocopy="true">0x0b</code> and <code data-nocopy="true">0x0c</code>). It's unclear what the precise difference is, but some random forum posts seem to suggest the LBA variant supports filesystems larger than 2GiB.</p>
      </div>
    </atom:content>
  </entry>
  <entry>
    <id>https://mallory.computer/posts/2025/05/31/vm-bhyve-freebsd-netbsd-openbsd.xml</id>
    <link href="/posts/2025/05/31/vm-bhyve-freebsd-netbsd-openbsd.html"/>
    <title>HOWTO: Install FreeBSD, NetBSD, OpenBSD using vm-bhyve</title>
    <published>2025-05-31T00:00:00Z</published>
    <updated>2025-05-31T00:00:00Z</updated>
    <atom:content xmlns="http://www.w3.org/1999/xhtml" type="xhtml">
      <div>
        <p>This HOWTO will present the steps of installing FreeBSD, NetBSD, and OpenBSD guests on a FreeBSD host using vm-bhyve. I'll assume <code data-nocopy="true">sysutils/vm-bhyve</code> is already installed and configured. See <code><a href="https://man.freebsd.org/cgi/man.cgi?query=vm">man vm</a></code> for configuration instructions.</p>
        <pre data-nocopy="true">% uname -srm
FreeBSD 14.2-RELEASE-p1 amd64

% vm version
vm-bhyve: Bhyve virtual machine management v1.6-devel (rev. 106001)</pre>
        <p>If you're using the <code data-nocopy="true">console</code> subcommand and you don't see anything, try pressing return. Also, note that there is no way to exit the <code data-nocopy="true">console</code> subcommand. You may need to close the terminal you are using entirely when you're done using it.</p>
        <h1 id="freebsd">Installing FreeBSD on FreeBSD</h1>
        <ol>
          <li>
            <p>Download the latest disc image.</p>
            <pre>vm iso https://download.freebsd.org/releases/amd64/amd64/ISO-IMAGES/14.2/FreeBSD-14.2-RELEASE-amd64-disc1.iso</pre>
          </li>
          <li>
            <p>Create an empty VM.</p>
            <pre>vm create -t default freebsd00</pre>
          </li>
          <li>
            <p>Start the VM using the installation image.</p>
            <pre>vm install freebsd00 FreeBSD-14.2-RELEASE-amd64-disc1.iso</pre>
          </li>
          <li>
            <p>Connect to the console of the VM.</p>
            <pre>vm console freebsd00</pre>
          </li>
          <li>
            <p>Proceed with the installation. The default options should work.</p>
          </li>
        </ol>
        <p>Configuration as seen with <code>vm configure freebsd00</code>:</p>
        <pre>loader="bhyveload"
cpu=1
memory=256M
network0_type="virtio-net"
network0_switch="public"
disk0_type="virtio-blk"
disk0_name="disk0.img"
uuid="1275e62d-e09c-496c-b4a7-6da2fd0e06f0"
network0_mac="58:9c:fc:0a:59:e9"</pre>
        <h1 id="netbsd">Installing NetBSD on FreeBSD</h1>
        <ol>
          <li>
            <p>Download the latest disc image.</p>
            <pre>vm iso https://cdn.netbsd.org/pub/NetBSD/NetBSD-10.1/images/NetBSD-10.1-amd64.iso</pre>
          </li>
          <li>
            <p>Create an empty VM using the pre-installed NetBSD template.</p>
            <pre>vm create -t netbsd netbsd00</pre>
          </li>
          <li>
            <p>Start the VM using the installation image.</p>
            <pre>vm install netbsd00 NetBSD-10.1-amd64.iso</pre>
          </li>
          <li>
            <p>Connect to the console of the VM.</p>
            <pre>vm console netbsd00</pre>
          </li>
          <li>
            <p>Proceed with the installation. The default options should work.</p>
          </li>
        </ol>
        <p>Configuration as seen with <code>vm configure netbsd00</code>:</p>
        <pre>loader="grub"
cpu=1
memory=256M
network0_type="virtio-net"
network0_switch="public"
disk0_type="virtio-blk"
disk0_name="disk0.img"
grub_install0="knetbsd -h -r cd0a /netbsd"
grub_run0="knetbsd -h -r dk0 /netbsd"
uuid="a525c553-c17f-46fc-95cd-535501038ff0"
network0_mac="58:9c:fc:0f:25:9e"</pre>
        <h1 id="openbsd">Installing OpenBSD on FreeBSD</h1>
        <ol>
          <li>
            <p>Download the latest disc image.</p>
            <pre>vm iso https://cdn.openbsd.org/pub/OpenBSD/7.7/amd64/install77.iso</pre>
          </li>
          <li>
            <p>Create an empty VM using the pre-installed OpenBSD template.</p>
            <pre>vm create -t openbsd openbsd00</pre>
          </li>
          <li>
            <p>Edit the configuration.</p>
            <pre>vm configure openbsd00</pre>
            <p>On the <code data-nocopy="true">grub_install0</code> line, change <code data-nocopy="true">6.2</code> to <code data-nocopy="true">7.7</code>.</p>
          </li>
          <li>
            <p>Start the VM using the installation image.</p>
            <pre>vm install openbsd00 install77.iso</pre>
          </li>
          <li>
            <p>Connect to the console of the VM.</p>
            <pre>vm console openbsd00</pre>
          </li>
          <li>
            <p>Proceed with the installation. The default options should work aside from:</p>
            <ul>
              <li>When installing to disk, use MBR instead of the default GPT.</li>
              <li>When asked to change the default console to <code data-nocopy="true">com0</code>, ensure you choose yes (this is the default).</li>
            </ul>
          </li>
        </ol>
        <p>Configuration as seen with <code>vm configure openbsd00</code>:</p>
        <pre>loader="grub"
cpu=1
memory=256M
network0_type="virtio-net"
network0_switch="public"
disk0_type="virtio-blk"
disk0_name="disk0.img"
grub_install0="kopenbsd -h com0 /7.7/amd64/bsd.rd"
grub_run0="kopenbsd -h com0 -r sd0a /bsd"
bhyve_options="-w"
uuid="02bd7294-3cfa-4ef2-ade9-f9d4546b544c"
network0_mac="58:9c:fc:00:83:f8"</pre>
      </div>
    </atom:content>
  </entry>
  <entry>
    <id>https://mallory.computer/posts/2025/07/04/transmission-openbsd-wireguard-pf.xml</id>
    <link href="/posts/2025/07/04/transmission-openbsd-wireguard-pf.html"/>
    <title>HOWTO: Install Transmission on OpenBSD 7.7</title>
    <published>2025-07-04T00:00:00Z</published>
    <updated>2026-04-18T00:00:00Z</updated>
    <atom:content xmlns="http://www.w3.org/1999/xhtml" type="xhtml">
      <div>
        <p>In this HOWTO I'll explain the process of installing Transmission on OpenBSD with a WireGuard VPN to conceal our real IP addresses. I'll use OpenBSD's <code data-nocopy="true">acme-client</code> to fetch a TLS certificate from Let's Encrypt, OpenBSD's <code data-nocopy="true">httpd</code> to serve a homepage and the downloads directory, and OpenBSD's <code data-nocopy="true">relayd</code> to forward HTTP requests to <code data-nocopy="true">transmission-daemon</code> or <code data-nocopy="true">httpd</code> depending on the URL.</p>
        <p>I'm assuming this will run on a home network, where IPv6 will simplify things since we won't need to worry about our internal vs external IPv4 addresses being different, and having DNS point to the same server.</p>
        <h2>Installing OpenBSD</h2>
        <p>You can mostly use the default options. I'll note where that differs.</p>
        <ul>
          <li>I'll set my hostname to <code data-nocopy="true"><em>torrent00</em></code> (I'll use <code data-nocopy="true"><em>this style</em></code> throughout this HOWTO for any values which you should change to suit your situation)</li>
          <li>I'm assigning my DNS records to point at an IPv6 address, so let's use <code>autoconf</code> when prompted for both IPv4 and IPv6 configurations</li>
          <li>I'll set the root user's password to <code>foobar</code> since I'll never be authenticating with that account (except via the VM's console)</li>
          <li>When prompted, I'll create a user called <code data-nocopy="true">openbsd</code> with no password</li>
          <li>Ensure that <code data-nocopy="true">sshd</code> is enabled during the installation</li>
          <li>
			At the end of the installation, I'll choose the <code data-nocopy="true">(S)hell</code> option to do some extra configuration before rebooting:
			<ul><li>Run <code>echo <em>torrent00.mydomain.invalid</em> &gt; /mnt/etc/myname</code> to tell OpenBSD your <abbr title="Fully Qualified Domain Name">FQDN</abbr></li><li>If you're installing in a VM, you may want to go ahead and set up your SSH key before first boot by running <code>cat &gt; /mnt/home/openbsd/.ssh/authorized_keys</code> and then pasting in your public key (press <code data-nocopy="true"><abbr title="Ctrl-D">^D</abbr></code> on an empty line to finish writing the file)</li><li>Run <code>chroot /mnt /usr/sbin/user mod -G wheel openbsd</code> to add the user to the wheel group</li><li>Run <code>echo permit nopass :wheel &gt; /mnt/etc/doas.conf</code> to allow members of the wheel group to use <code data-nocopy="true">doas</code> without a password</li><li>Run <code>echo inet6 alias <em>2001:db8::1234</em>/128 &gt; /mnt/etc/hostname.<em>vio0</em></code> to set a static <abbr title="Globally Unique Address">GUA</abbr>, ensuring that <code data-nocopy="true"><em>2001:db8::1234</em></code> is an address within the range your router can use, and setting <code data-nocopy="true"><em>vio0</em></code> to the name of the interface</li><li>Create a DNS record to point the AAAA record of <code data-nocopy="true"><em>torrent00.mydomain.invalid</em></code> at your address. You'll then be able to use <code>ssh openbsd@<em>torrent00.mydomain.invalid</em></code> to SSH in</li></ul>
		</li>
        </ul>
        <h2>First boot and miscellaneous configuration</h2>
        <ul>
          <li>Run <code>doas syspatch</code> because <code data-nocopy="true">rc.firsttime</code> says you should</li>
          <li>Use Quad9's unfiltered DNS resolver: <code>echo -en 'nameserver 2620:fe::fe\nnameserver 9.9.9.10\nlookup file bind\n' | doas tee /etc/resolv.conf</code></li>
          <li>Install additional packages: <code>doas pkg_add transmission wireguard-tools</code></li>
          <li>You'll need to configure your firewall to allow incoming connections to <code data-nocopy="true"><em>torrent00.mydomain.invalid</em></code> port 80, TCP. This is necessary for getting a certificate using the ACME protocol</li>
        </ul>
        <h2>Configuring httpd, relayd, acme-client, and Transmission</h2>
        <ul>
          <li>
            <code>doas mkdir /var/www/htdocs/downloads</code>
          </li>
          <li>
            <code>doas chown _transmission:_transmission /var/www/htdocs/downloads</code>
          </li>
          <li>
            <code>doas rcctl enable transmission &amp;&amp; doas rcctl set transmission_daemon flags '--download-dir=/var/www/htdocs/downloads --global-seedratio=5'</code>
          </li>
          <li>Run <code>echo transmission_daemon:openfiles=65535 | doas tee /etc/login.conf.d/transmission_daemon</code>. This will create a new login class called "transmission_daemon" and set the maximum open files to 65535. The default for the "daemon" login class is only 128 which will cause Transmission to report "Too many open files" errors</li>
          <li>
            <pre>cat &lt;&lt;EOF | doas tee /etc/acme-client.conf
authority letsencrypt {
        api url "https://acme-v02.api.letsencrypt.org/directory"
        account key "/etc/acme/letsencrypt-privkey.pem"
}

domain <em>torrent00.mydomain.invalid</em> {
	domain key "/etc/ssl/private/<em>torrent00.mydomain.invalid</em>.key"
	domain full chain certificate "/etc/ssl/<em>torrent00.mydomain.invalid</em>.crt"
        sign with letsencrypt
}
EOF</pre>
          </li>
          <li>
            <pre>cat &lt;&lt;EOF | doas tee /etc/httpd.conf
# Handle ACME challenges and redirect to https://
server "<em>torrent00.mydomain.invalid</em>" {
        listen on * port 80
        location "/.well-known/acme-challenge/*" {
                root "/acme"
                request strip 2
        }
        location * {
                block return 302 "https://\$HTTP_HOST\$REQUEST_URI"
        }
}

# Serve the homepage and downloads directory
server "<em>torrent00.mydomain.invalid</em>" {
        listen on * port 8080
        location "/downloads/*" {
                directory auto index
        }
}
EOF</pre>
          </li>
          <li>
            <pre>cat &lt;&lt;EOF | doas tee /etc/relayd.conf
table &lt;transmission&gt; { 127.0.0.1 }
table &lt;httpd&gt; { ::1 }
http protocol https {
        tls { keypair <em>torrent00.mydomain.invalid</em> }

        match request path "/" header set "Host" value "[::1]:8080"
        match request path "/" forward to &lt;httpd&gt;

        match request path "/downloads/*" header set "Host" value "[::1]:8080"
        match request path "/downloads/*" forward to &lt;httpd&gt;

        match request path "/transmission/*" header set "Host" value "127.0.0.1:9091"
        match request path "/transmission/*" forward to &lt;transmission&gt;
}
relay httpproxy {
        protocol https
        listen on :: port 443 tls
        forward to &lt;httpd&gt; port 8080
        forward to &lt;transmission&gt; port 9091
}
EOF</pre>
          </li>
          <li>
            <pre>cat &lt;&lt;EOF | doas tee /var/www/htdocs/index.html
&lt;title&gt;<em>torrent00.mydomain.invalid</em>&lt;/title&gt;
&lt;link rel="icon" href="/transmission/web/images/favicon.png"&gt;
&lt;h1&gt;<em>torrent00.mydomain.invalid</em>&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="/transmission/web/"&gt;Transmission&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/downloads/"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
EOF</pre>
          </li>
          <li>
            <code>doas rcctl enable relayd httpd transmission_daemon</code>
          </li>
          <li>
            <code>doas rcctl start httpd transmission_daemon</code>
          </li>
          <li>
			Set up acme-client to run once an hour, at a random minute:
			<code>doas crontab -e</code><br/>
			Then add the following:<br/>
			<code>~ * * * * acme-client <em>torrent00.mydomain.invalid</em> &amp;&amp; rcctl reload relayd httpd</code>
		</li>
          <li>
            <code>doas acme-client <em>torrent00.mydomain.invalid</em> &amp;&amp; doas rcctl reload httpd &amp;&amp; doas rcctl start relayd</code>
          </li>
        </ul>
        <h2>Configuring WireGuard</h2>
        <ul>
          <li>
            <code>doas mkdir /etc/wireguard</code>
          </li>
          <li><code>doas cp <em>my-wireguard-config.conf</em> /etc/wireguard/wg0.conf</code><br/>
			Note: While writing this guide, I found that when <code data-nocopy="true">Endpoint</code> in the configuration file is an IPv6 address, WireGuard doesn't work.
		</li>
          <li>
            <code>doas chmod 600 /etc/wireguard/wg0.conf</code>
          </li>
          <li>
            <pre>cat &lt;&lt;EOF | doas tee /etc/rc.d/wireguard
#!/bin/ksh

daemon="/usr/local/bin/wg-quick"
daemon_flags="wg0"

. /etc/rc.d/rc.subr

rc_start() {
        "\${daemon}" up "\${daemon_flags}"
}

rc_stop() {
        "\${daemon}" down "\${daemon_flags}"
}

rc_check() {
        ifconfig "\${daemon_flags}"
}

rc_reload() {
        rc_stop
        rc_start
}

rc_cmd \$1
EOF</pre>
          </li>
          <li>
            <code>doas chmod 755 /etc/rc.d/wireguard</code>
          </li>
          <li>
            <code>doas rcctl enable wireguard</code>
          </li>
          <li>
            <code>doas rcctl start wireguard</code>
          </li>
          <li>Verify your IPv4 and IPv6 addresses have changed: <code>ftp -VMo- https://ip4only.me/api/ ; ftp -VMo- https://ip6only.me/api/</code></li>
        </ul>
        <h2>Configuring the packet filter</h2>
        <p>This is necessary to prevent Transmission from accessing the internet when WireGuard is down.</p>
        <ul>
          <li>
            <pre>cat &lt;&lt;EOF | doas tee -a /etc/pf.conf

# Block all incoming connections from wg0
block in on wg0

# Prevent leaks from Transmission
block proto tcp user _transmission
block proto udp user _transmission
pass on wg0 proto tcp user _transmission
pass on wg0 proto udp user _transmission
EOF</pre>
          </li>
          <li>Reload PF's configuration with <code>doas pfctl -f /etc/pf.conf</code></li>
          <li>
			Now we'll turn off WireGuard to check that the Transmission user can't call out:<br/>
			<code>doas rcctl stop wireguard</code><br/>
			<code>doas -u _transmission sh -c 'ftp -VMo- https://ip4only.me/api/ ; ftp -VMo- https://ip6only.me/api/'</code><br/>
			And you should see:<br/>
			<pre data-nocopy="true">ftp: ip4only.me: no address associated with name
ftp: ip6only.me: no address associated with name</pre>
		</li>
          <li>
			Then we'll switch WireGuard back on and make sure we see our VPN's IP address:<br/>
			<code>doas rcctl start wireguard</code><br/>
			<code>doas -u _transmission sh -c 'ftp -VMo- https://ip4only.me/api/ ; ftp -VMo- https://ip6only.me/api/'</code><br/>
		</li>
        </ul>
        <h2>Finishing touches</h2>
        <ul>
          <li>Run <code>ln -s /var/www/htdocs/downloads</code> to put a symlink to the downloads directory in <code data-nocopy="true">~</code></li>
          <li>
            <pre>cat &lt;&lt;EOF &gt; test.sh
#!/bin/ksh

whoami
ftp -VMo- http://ip6only.me/api/ | cut -d, -f2
ftp -VMo- http://ip4only.me/api/ | cut -d, -f2

doas -u _transmission whoami
doas -u _transmission ftp -VMo- http://ip6only.me/api/ | cut -d, -f2
doas -u _transmission ftp -VMo- http://ip4only.me/api/ | cut -d, -f2
EOF</pre>
          </li>
          <li>
            <code>chmod 755 test.sh</code>
          </li>
          <li><code>doas reboot</code> to ensure when we reboot everything comes up</li>
          <li>One final test: <code>./test.sh &amp;&amp; doas rcctl stop wireguard &amp;&amp; ./test.sh &amp;&amp; doas rcctl start wireguard</code></li>
          <li>Now your Transmission server is running at <code>https://<em>torrent00.mydomain.invalid</em></code>!</li>
        </ul>
      </div>
    </atom:content>
  </entry>
</feed>
