Jan 01

How to Install and Configure: ruTorrent, rTorrent (Debian 9 Stretch).

Add your username to /etc/sudoers.


Root password.

apt-get install sudo
nano /etc/sudoers


joe         ALL=(ALL) ALL

1. Create new user “rtorrent” and home directory.

home directory: /opt/rtorrent.

sudo adduser -s /sbin/nologin --home /opt/rtorrent rtorrent

2. Update system/server.

sudo apt-get update
sudo apt-get upgrade

3. Install some needed dependencies: Apache2, PHP7 etc.

sudo apt-get -y install php php-geoip php7.0-cli php7.0-json php7.0-curl php7.0-cgi php7.0-mbstring libapache2-mod-php libapache2-mod-scgi libapache2-mod-xsendfile apache2 unrar unzip libav-tools ffmpeg mediainfo curl screen sqlite3 git net-tools sox

4. Install rtorrent.

sudo apt-get -y install rtorrent libtorrent19 libxmlrpc-core-c3

5. Create directories, these are needed for rTorrent to function.

sudo mkdir -p /opt/rtorrent/{session,watch,download}
sudo chmod 777 -R /opt/rtorrent/{session,watch,download}
sudo chown rtorrent:rtorrent -R /opt/rtorrent/{session,watch,download}

6. Download .rtorrent.rc file and put it in the home directory of the user that will run rTorrent.

Default directory: /opt/rtorrent/.

sudo wget --no-check-certificate https://terminal28.com/download/.rtorrent.rc-new -O /opt/rtorrent/.rtorrent.rc
sudo chmod 777 /opt/rtorrent/.rtorrent.rc

Example .rtorrent.rc:

# Port SCGI
scgi_port = localhost:5000

#This is an example resource file for rTorrent. Copy to

# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
throttle.min_peers.normal.set = 40
throttle.max_peers.normal.set = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
throttle.min_peers.seed.set = 10
throttle.max_peers.seed.set = 100

# Maximum number of simultanious uploads per torrent.
throttle.max_uploads.set = 15

# Global upload and download rate in KiB. "0" for unlimited.
throttle.global_down.max_rate.set_kb = 0
throttle.global_up.max_rate.set_kb = 8

# Default directory to save the downloaded torrents.
directory.default.set = /opt/rtorrent/download

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session.path.set = /opt/rtorrent/session

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule2 = watch_directory,5,5,load_start=/opt/rtorrent/session/*.torrent
schedule2 = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
schedule2 = low_diskspace,5,60,close_low_diskspace=2000M

# The ip address reported to the tracker.
#network.local_address.set =
#network.local_address.set = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#network.bind_address.set =
#network.bind_address.set = rakshasa.no

# Port range to use for listening.
network.port_range.set = 6890-6999

# Start opening ports at a random position within the port range.
network.port_random.set = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
pieces.hash.on_completion.set = no

# Set whether the client should try to connect to UDP trackers.
trackers.use_udp.set = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule2 = ip_tick,0,1800,ip=rakshasa
#schedule2 = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
protocol.encryption.set = allow_incoming,enable_retry,prefer_plaintext

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
dht.mode.set = auto

# UDP port to use for DHT.
dht.port.set = 6881

# Enable peer exchange (for torrents not marked private)
protocol.pex.set = yes

# Set downlad list layout style. ("full", "compact")
#ui.torrent_list.layout.set = "full"

7. Install and configure ruTorrent.

7.1. ruTorrent via GIT.
sudo git clone https://github.com/Novik/ruTorrent.git /var/www/rutorrent/
sudo chown -R www-data:www-data /var/www/rutorrent
7.2. ruTorrent mobile.

Acces to ruTorrent, rTorrent from Apple smartphones and older smartphones.


Acces to ruTorrent, rTorrent from Android smartphones.


Update path to Download directory.

Edit ruTorrent’s config.php config file and change path to Download directory.

Locate $topDirectory and add path to Download directory (/opt/rtorrent/download):

sudo nano /var/www/rutorrent/conf/config.php
$topDirectory = '/opt/rtorrent/download'; // Upper available directory. Absolute path with trail slash.

Some apps might not be in default location.
Use whereis app to find binary files and then update lines in config file. See below.

whereis gzip
gzip: /bin/gzip /usr/share/man/man1/gzip.1.gz /usr/share/info/gzip.info.gz
$pathToExternals = array(
"php" => '/usr/bin/php', // Something like /usr/bin/php. If empty, will be found in PATH.
"curl" => '/usr/bin/curl', // Something like /usr/bin/curl. If empty, will be found in PATH.
"gzip" => 'bin/gzip', // Something like /usr/bin/gzip. If empty, will be found in PATH.
"id" => '/usr/bin/id', // Something like /usr/bin/id. If empty, will be found in PATH.
"stat" => '/usr/bin/stat', // Something like /usr/bin/stat. If empty, will be found in PATH.

8. Install GeoIP database.

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
sudo gunzip GeoLiteCity.dat.gz
sudo mkdir -v /usr/share/GeoIP
sudo mv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat

9. Secure ruTorrent web access.

Create the .htpasswd file.

cd /var/www/rutorrent
sudo htpasswd -c /var/www/rutorrent/.htpasswd nazwa_użytkownika

You will be asked for a password twice.


New password:
Re-type new password:
Adding password for user username

Edit file /var/www/rutorrent/.htaccess and add location secured by password.

sudo nano /var/www/rutorrent/.htaccess
AuthUserFile /var/www/rutorrent/.htpasswd
AuthName "ruTorrent_login"
AuthType Basic
require valid-user

10. Configure access to ruTorrent.

Edit /etc/apache2/sites-available/rutorrent and add infoformation about: alias, files and location secured by password.

sudo nano /etc/apache2/sites-available/rutorrent.conf
# ruTorrent
<IfModule alias_module>

Alias /rutorrent        /var/www/rutorrent/ 

        <Directory /var/www/rutorrent/>
                Options +Indexes +Includes +FollowSymLinks +MultiViews
                AllowOverride all
                Require all granted


Enable ruTorrent WebUI.

sudo ln -s /etc/apache2/sites-available/rutorrent.conf /etc/apache2/sites-enabled/rutorrent.conf

11. Activate Apache2 modules.

sudo a2enmod auth_digest
sudo a2enmod authn_file
sudo a2enmod xsendfile
sudo a2enmod scgi

12. Secure SCGI (/RPC2) directory.

Create folders: passwords-available, passwords-enabled in /etc/apache2.

sudo mkdir -p /etc/apache2/passwords-{available,enabled}

Go to /etc/apache2/passwords-available and make a new password for SCGI.

cd /etc/apache2/passwords-available
sudo htpasswd -c rtorrentscgi username

Enable rtorrentscgi password.

Link folder passwords-available to passwords-enabled.

sudo ln -s /etc/apache2/passwords-available/rtorrentscgi /etc/apache2/passwords-enabled/rutorrent

Edit file /etc/apache2/sites-available/rtorrentscgi and add location of SCGI secured by password.

sudo nano /etc/apache2/sites-available/rtorrentscgi.conf
#rTorrent SCGI Password Location
        <LocationMatch "/RPC2">
                AuthType        Basic
                AuthName        "rtorrentscgi"
                AuthUserFile    /etc/apache2/passwords-enabled/rtorrentscgi
                Require         valid-user
                BrowserMatch    "MSIE"  AuthDigestEnableQueryStringHack=On
                Require ip


#LoadModule scgi_module /usr/lib/apache2/modules/mod_scgi.so


Enable rtorrentscgi config.

sudo ln -s /etc/apache2/sites-available/rtorrentscgi.conf /etc/apache2/sites-enabled/rtorrentscgi.conf

Restart Apache2 server.

sudo service apache2 restart

13. Autostart rTorrent – systemd.

Create rtorrent autostart script for systemd.

sudo nano /etc/systemd/system/rtorrent.service

ExecStartPre=-/bin/rm -f /opt/rtorrent/session/rtorrent.lock
ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 /usr/bin/rtorrent


Enable rTorrent autostart..

sudo systemctl enable rtorrent.service

From now rTorrent will start with system automatically in a detached shell using screen.


sudo service rtorrent start       - uruchamianie
sudo service rtorrent stop        - zatrzymywanie
sudo service rtorrent restart     - restart


sudo systemctl start rtorrent     - uruchamianie
sudo systemctl stop rtorrent      - zatrzymywanie
sudo systemctl restart rtorrent   - restar

14. Start service rTorrent.

sudo service rtorrent start

Testing rTorrent:

sudo netstat -npl | grep rtorrent


tcp    0 0*    LISTEN 16229/rtorrent
tcp    0 0*    LISTEN 16229/rtorrent
udp    0 0*    16229/rtorrent

Access to your web front-end for rTorrent.

http://IP address/rutorrent



You should be asked for username and password to access website



Leave a Reply

Your email address will not be published.