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

[important]

Tested:

  • Debian 9.x.x,
  • rTorrent ver: 9.6,
  • Libtorrent ver: 13.6,
  • ruTorrent 3.7 – git,
  • Apache 2.4.x.

[/important]

Add your username to /etc/sudoers.

su

Root password.

apt-get install sudo
nano /etc/sudoers

Example:

joe         ALL=(ALL) ALL

Adding unrar to the APT list.

sudo nano /etc/apt/sources.list

Add these: main contrib non-free at the end of each link line e.g.

deb http://http.debian.net/debian stretch-backports main contrib non-free

then update, upgrade and install unrar

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install unrar

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

home directory: /opt/rtorrent.

Debian 9.5+.

sudo adduser --disabled-login --disabled-password --home /opt/rtorrent --system rtorrent

Debian 8-9.

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 = 127.0.0.1
#network.local_address.set = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#
#network.bind_address.set = 127.0.0.1
#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.

http://terminal28.com/access-to-rutorrent-rtorrent-from-iphone-and-older-mobile-phones/

Acces to ruTorrent, rTorrent from Android smartphones.

http://www.transdroid.org/.

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
Output:
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.

Output:

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
        </Directory>

</IfModule>
#===========================================================================

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/rtorrentscgi

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 127.0.0.1
        </LocationMatch>
#===========================================================================

# SCGI PORT
#===========================================================================

#LoadModule scgi_module /usr/lib/apache2/modules/mod_scgi.so
SCGIMount /RPC2 127.0.0.1:5000

#===========================================================================

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
[Unit]
Description=rTorrent
After=network.target

[Service]
UMask=002
Type=forking
RemainAfterExit=yes
KillMode=none
User=rtorrent
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
WorkingDirectory=/opt/rtorrent/

[Install]
WantedBy=multi-user.target

Enable rTorrent autostart..

sudo systemctl enable rtorrent.service

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

Commands:

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

or

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

Output:

tcp    0 0    127.0.0.1:5000    0.0.0.0:*    LISTEN 16229/rtorrent
tcp    0 0    0.0.0.0:6890      0.0.0.0:*    LISTEN 16229/rtorrent
udp    0 0    0.0.0.0:6881      0.0.0.0:*    16229/rtorrent

Access to your web front-end for rTorrent.

http://IP address/rutorrent

or

http://domain/rutorrent

You should be asked for username and password to access website

Links:
http://libtorrent.rakshasa.no/
http://code.google.com/p/rutorrent/
http://code.google.com/p/avalanche-rt/

[notice]

[notice]
Support my work by donation. Thank You.

[/notice]

21 comments

Skip to comment form

    • Eduardo on 13 September 2018 at 03:45
    • Reply

    great tutorial, thanks
    works on ubuntu 16.04, with a minor correction to “adduser” command: sudo adduser –home /opt/rtorrent –disabled-login rtorrent

    1. Fixed.
      Thank you.

    • NA on 14 October 2018 at 20:28
    • Reply

    E: Package ‘unrar’ has no installation candidate

    1. unrar is non-free version, you have to change settings in nano /etc/apt/sources.list to get it..

    • GRAEME on 29 October 2018 at 15:55
    • Reply

    im on Debian 9 but the first command to adduser dont work

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

    and i get

    Option s is ambiguous (shell, system)

    1. Fixed.
      Thank you.

    • Ns on 9 November 2018 at 14:42
    • Reply

    Nice job! As clear as the Debian 8 version 🙂

    Thanks for sharing,
    Nico.

    • Ns. on 29 November 2018 at 12:45
    • Reply

    Hi,

    Thank you for your work!

    Question: I get several errors when i add torrent like:
    – Tracker: [Timeout was reached]
    – Tracker: [Timeout was reached]

    for information rtorrent is running inside a Vhost ( proxmox CT)

    cheers,
    Ns.

    1. maybe tracker down or connection problem?

    • nS. on 4 February 2019 at 14:55
    • Reply

    Hi,

    Thanks a lot for your work!

    Just one thing in point 12:

    AuthUserFile /etc/apache2/passwords-enabled/rtorrentscgi

    should be :

    AuthUserFile /etc/apache2/passwords-enabled/rtorrent

    isn’t it ? because of the link name.

    Last point: Could you please explain us how to add an new user with your configuration ?

    Cheers,
    nS.

    1. Fixed it.
      Thank you.

      Adduser command has some change, so its fixed.

      sudo adduser --disabled-login --disabled-password --home /opt/rtorrent --system rtorrent

      and symlink fixed as well

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

      AuthUserFile /etc/apache2/passwords-enabled/rtorrentscgi

    • IFFI on 25 June 2019 at 17:21
    • Reply

    Hi,

    Thanks a lot for your work! But how to change upload speed limit? Current speed max 8kb/s

    Cheers
    IFFI

    1. edit .rtorrent.rc
      throttle.global_up.max_rate.set_kb = 100
      (100 kilobytes e.t.c)

      or you can change it in rutorrent:
      klick on blue sprocket icon > Connection tab > Global maximum upload rate and set there in kilobytes

    • Bajza Ferenc on 13 July 2019 at 19:45
    • Reply

    Hi,

    Thanks for this tutorial! I reproduced these steps, but I have this below error on ruTorrent:
    “No connection to rTorrent. Check if it is really running. Check $scgi_port and $scgi_host settings in config.php and scgi_port in rTorrent configuration file.”

    All of these settings has been set as you wrote in this tutorial, but it’s still not working. Can you help me?

    Thank you!

    1. I think there is some change in .rtorrent.rc
      sudo nano /opt/rtorrent/.rtorrent.rc
      Remove this:
      scgi_port = 127.0.0.1:5000
      and add this:
      network.scgi.open_port = "127.0.0.1:5000"
      Make sure this file has been created – step 12:
      /etc/apache2/sites-available/rtorrentscgi
      and is linked to
      /etc/apache2/sites-enabled/rtorrentscgi
      Make sure these are in rutorrent’s config.php
      sudo nano /var/www/rutorrent/conf/config.php
      $scgi_port = 5000;
      $scgi_host = "127.0.0.1";

      And make sure these packages are installed:
      libapache2-mod-scgi, libxmlrpc-core-c3

        • Bajza Ferenc on 14 July 2019 at 22:41
        • Reply

        Thank for this very fast reply! Unfortunately none of them helped me.
        Can I send to you my config files somehow? For example by email.

        Thanks!

        1. Use this website https://pastebin.com/ to paste your configs (apache2 rutorrent, rtorrentscgi, rtorrent.rc, etc) and set expire after 1 week cos I won’t have time to check it in next few days..
          then paste links in comments.
          You can try do this tutorial again but carefully and overwrite everything. Make sure that symlinks are created. You could miss something..

            • Bajza Ferenc on 15 July 2019 at 10:03

            Okay, it was my fault. I not changed to my path the home directory of rtorrent user at the beginning. After I changed it, works well.

            Thanks for the help!

    • scouse on 26 August 2019 at 20:43
    • Reply

    I wonder if someone can help me I am trying to run rtorrent as either a none system user or as root, but it won’t work, is there any reason why the user needs to be a system user in order for it to run and is there any way to get around it?

    I have tried everything including changing the permissions on /opt/rtorrent and amending rtorrent.service but it still won’t work.
    Any advice would be most appreciated.

    Thanks for the great guide!!!

    1. Every app on linux/unix runs with system user, there is no any non, virtual etc user.
      The easy way is to run app as user admin/root so you can run any app with no any problems.
      If you are trying to run rtorrent as root then in root folder you will have to place config file rtorrent.rc – permission for folders don’t matter.
      Root have access: read/write/exec.. to everything on the system.
      You will have to change user in rtorrent.service as well.
      Make sure you have installed everything and you didn’t miss anything from tutorial.
      Change permission to chmod 777 -R /opt/rtorrent, this should work well but everyone will have access to it.

        • scouse on 27 August 2019 at 21:16
        • Reply

        That worked perfectly, thanks very much…

Leave a Reply

Your e-mail address will not be published.