cmc/cleberg.net
My personal web garden & blog.
clone: git clone https://gitbay.org/cmc/cleberg.net.git
main: content/blog/2024-09-23-self-hosting-transmission.org · raw
1#+date: [2024-09-23 Mon 19:52:20]
2#+title: Self-Hosting Guide: Transmission
3#+description: Setting up Transmission on a Linux server with Nginx for remote access.
4#+slug: self-hosting-transmission
5#+filetags: :linux:self-hosting:
6
7#+begin_quote
8If you're torrenting anything sensitive, I *highly* recommend you use a VPN.
9Something like mullvad-cli is incredibly simple to use and can be configured to
10have a "killswitch" or "lockdown mode" to ensure that if the VPN disconnects,
11your traffic won't be leaked to your ISP.
12#+end_quote
13
14* Transmission
15
16[[https://transmissionbt.com/][Transmission]] is a cross-platform bittorrent client that supports running a
17[[https://linux.die.net/man/1/transmission-remote][remote control utility]], a [[https://linux.die.net/man/1/transmission-daemon][daemon service]] for running as a background service,
18and a [[https://linux.die.net/man/1/transmission-cli][command-line client]].
19
20Since I love torrenting Linux ISOs and providing them back to the community,
21let's walk through a tutorial of setting up Transmission on a headless server
22and connecting it to a domain name (=transmission.example.com=) so that we can
23manage our torrents remotely.
24
25This tutorial assumes you have a Linux machine, have Nginx installed, and have a
26domain name pointing at your Linux machine.
27
28** Installation
29
30First, let's install a couple Transmission packages on the system. We don't need
31the GUI components, so we'll only install the daemon and command line interface
32utilities.
33
34#+begin_src sh
35sudo apt install transmission-cli transmission-common transmission-daemon
36#+end_src
37
38You will need to run the program to initialize the files before you can edit the
39configurations, so let's run it and end the process.
40
41#+begin_src sh
42# Run the program
43transmission-daemon -e ~/.local/log/transmission.log
44
45# End the program after it finishes running
46transmission-remote --exit
47#+end_src
48
49** Configuration
50
51Now that we've run the program for the first time and initialized the relevant
52files, let's edit those files.
53
54#+begin_quote
55If you edit the files while Transmission is running, your changes won't be
56saved! Make sure to end the service, update the configuration files, and restart
57the service.
58#+end_quote
59
60To start, let's edit the main configuration file.
61
62#+begin_src sh
63nano ~/.config/transmission-daemon/settings.json
64#+end_src
65
66Within this file, I suggesting skimming *every* option and determining if you
67want to change any of those options.
68
69For remote access, we will focus on the following =rpc= options. This
70configuration will not require authentication, will allow any device with access
71(I suggest that you have a firewall restricting access) to access the service
72(="rpc-bind-access": "0.0.0.0"=), will open the service on port =9091=, and will
73whitelist a few LAN IPs (="rpc-whitelist":
74"127.0.0.1,::1,192.168.0.98,192.168.0.97"=).
75
76#+begin_src json
77{
78 ...
79 "rpc-authentication-required": false,
80 "rpc-bind-address": "0.0.0.0",
81 "rpc-enabled": true,
82 "rpc-host-whitelist": "",
83 "rpc-host-whitelist-enabled": true,
84 "rpc-password": "{7fc02520b97e054f7a15274c7cfafe3cd7330169.OQUAUS4",
85 "rpc-port": 9091,
86 "rpc-socket-mode": "0750",
87 "rpc-url": "/transmission/",
88 "rpc-username": "",
89 "rpc-whitelist": "127.0.0.1,::1,192.168.0.98,192.168.0.97",
90 "rpc-whitelist-enabled": true,
91 ...
92}
93#+end_src
94
95Once you've finished configuring the service, start the service up again.
96
97#+begin_src sh
98transmission-daemon -e ~/.local/log/transmission.log
99#+end_src
100
101At this point, you should be able to access the website at =localhost:9091= (if
102you're browsing on the machine where Transmission is running) or
103=$server_ip:9091= (if you're browsing from a different LAN device).
104
105If you want to make further changes to Transmission's configuration, I suggest
106doing so now. Once you start working on remote access via a reverse proxy,
107you'll be adding an additional layer of complexity that bring in more confusion
108when errors occur.
109
110#+begin_quote
111NOTE: If you are trying to initialize =transmission-daemon= via =systemd=
112instead of using the manually-executed command above, you may notice that the
113service will timeout and fail to start.
114#+end_quote
115
116To fix this timeout issue, you need to edit the service file and change
117=Type=notify= to =Type=simple=.
118
119#+begin_src shell
120# Command to edit the service file:
121sudo systemctl edit --full transmission-daemon.service
122
123# Make the edit noted above and then reload the service file with this command:
124sudo systemctl daemon-reload
125sudo systemctl enable transmission-daemon.service
126sudo systemctl start transmission-daemon.service
127#+end_src
128
129* Reverse Proxy
130
131Now that the service is running and configured properly, let's work on remote
132access.
133
134This tutorial will use Nginx, but you can use any reverse proxy or something
135like Cloudflare Tunnels if that's your thing.
136
137** Configuration
138
139If you have Nginx installed, you should have either the =/etc/nginx/conf.d= or
140=/etc/nginx/sites-available= directories available to create website
141configuration files. This tutorial assumes the =conf.d= structure, but it's
142essentially the same except using the =sites-available= structure requires you
143to symlink your files into the =sites-enabled= directory.
144
145Let's start by creating the website configuration file.
146
147#+begin_src sh
148sudo nano /etc/nginx/conf.d/transmission.conf
149#+end_src
150
151Within the file, you will need a configuration similar to the code below. Note
152that this uses SSL and requires a valid TLS/SSL certificate. You can use [[https://letsencrypt.org/][Let's
153Encrypt]] if you don't have a certificate yet.
154
155#+begin_src conf
156server {
157 listen 443 ssl;
158 listen [::]:443 ssl;
159 http2 on;
160 server_name transmission.example.com;
161
162 # SSL
163 ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
164 ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
165 ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
166
167 # reverse proxy
168 location / {
169 set $upstream_transmission http://localhost:9091;
170 proxy_pass $upstream_transmission;
171 proxy_pass_header X-Transmission-Session-Id;
172 }
173}
174
175# HTTP redirect
176server {
177 listen 80;
178 listen [::]:80;
179 server_name transmission.example.com;
180
181 if ($host ~ ^[^.]+\.example\.com) {
182 return 301 https://$host$request_uri;
183 }
184}
185#+end_src
186
187Once you've saved the configuration file, restart the Nginx web server to enable
188the remote access connection.
189
190#+begin_src sh
191sudo systemctl restart nginx.service
192#+end_src
193
194At this point, Transmission should now be available at
195=transmission.example.com=, same as it's available on the LAN.
196
197#+begin_quote
198Pro Tip: If you dislike something about the website UI, you can edit the
199website's files in the =/usr/share/transmission/public_html/= directory. You can
200modify the HTML, CSS, and JS files in this directory.
201#+end_quote