Aug 10, 2018

Apt-get install error

You may get following error when you use apt-get install command.
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
Run ps command to see which processes are using apt.
# ps aux | grep apt
root       3701  0.0  0.0   4628   772 ?        Ss   01:17   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily install
root       3705  0.0  0.0   4628  1680 ?        S    01:17   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held install
_apt       3744  0.5  0.4  88960  8560 ?        S    01:18   0:00 /usr/lib/apt/methods/http
root       3755  0.0  0.0  21536  1000 pts/0    S+   01:18   0:00 grep --color=auto apt
Kill processes
# kill -9 3701
# kill -9 3705
# kill -9 3744
Check ps
# ps aux | grep apt
root       3757  0.0  0.0  21536  1028 pts/0    S+   01:18   0:00 grep --color=auto apt
After killing processes and restart apt-get install command I could install packages.

If you have interrupted apt-get session when you install a package you may see an error.
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.
In this case to continue setup run:
sudo dpkg --configure -a

Aug 4, 2018

Serve transmission torrent client on Nginx

Transmission web runs on localhost.
http://127.0.0.1:9091/transmission/web/
To make web interface reachable from WAN you can use nginx.

Edit nginx default settings file

/etc/nginx/sites-available$ sudo nano default

server {
       listen 9092;
       listen [::]:9092;

       server_name _;

 add_header Strict-Transport-Security max-age=31536000;

       location / {
         proxy_read_timeout 300;
         proxy_pass_header  X-Transmission-Session-Id;
         proxy_set_header   X-Forwarded-Host   $host;
         proxy_set_header   X-Forwarded-Server $host;
         proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;       
         proxy_pass         http://127.0.0.1:9091/transmission/web/;
     }
       
     location /rpc {
         proxy_pass         http://127.0.0.1:9091/transmission/rpc;
     }
       
     location /upload {
         proxy_pass         http://127.0.0.1:9091/transmission/upload;
     }
}
We opened port 9092 to internet. Don't forget give permission on firewall for that port.
http://your_website:9092/

Aug 2, 2018

Linux torrent client - transmission-remote

This article shows installing, configure transmission remote package. Some configurations passed to see errors and how to fix them. If you already installed transmission-cli package you can use remote package:
$ sudo transmission-remote --download-dir "/home/ubuntu/Downloads" -a magnet:?xt=urn:btih:2c83f573753d9e987a5bf0fcf8979c4aa137e869&dn=Linux All-In-One For Dummies, 6th Edition&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.opentrackr.org:1337&tr=udp://tracker.pirateparty.gr:6969&tr=udp://eddie4.nl:6969 
Unlike cli package, remote package works on background. It does not refresh status on terminal. Use following parameter to see status of download.
$ transmission-remote -l

Error#1: (http://localhost:9091/transmission/rpc/) Couldn't connect to server

If you see following error then you may not installed daemon or not started it.
[2018-07-29 12:53:33.664] transmission-remote:  (http://localhost:9091/transmission/rpc/) Couldn't connect to server
[2]+  Exit 127                dn=Linux All-In-One For Dummies, 6th Edition
You can install all services from beginning.
$ sudo apt-get update
$ sudo apt-get install transmission-cli transmission-common transmission-daemon
After installation, stop daemon and check settings.
$ sudo service transmission-daemon stop

$ cat /var/lib/transmission-daemon/info/settings.json
Settings not included in this article.
I only changed following parameter to give full access to files/folders created by transmission.
"umask": 2,
Start and check service.
$ sudo service transmission-daemon start

$ ps aux | grep transmission
debian-+ 12324  0.0  0.7 282064  7664 ?        Ssl  13:06   0:00 /usr/bin/transmission-daemon -f --log-error
root     12371  0.0  0.1  14856  1100 pts/0    S+   13:08   0:00 grep --color=auto transmission

$ netstat -tapen | grep transmission
tcp        0      0 0.0.0.0:9091            0.0.0.0:*               LISTEN      113        137537     12324transmission- 
tcp        0      0 0.0.0.0:51413           0.0.0.0:*               LISTEN      113        137538     12324transmission- 
tcp6       0      0 :::51413                :::*                    LISTEN      113        137540     12324transmission-  
Now service is working.

Error#2: Unauthorized User


Start torrent again.
$ sudo transmission-remote --download-dir "/home/ubuntu/Downloads" -a magnet:?xt=urn:btih:2c83f573753d9e987a5bf0fcf8979c4aa137e869&dn=Linux All-In-One For Dummies, 6th Edition&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.opentrackr.org:1337&tr=udp://tracker.pirateparty.gr:6969&tr=udp://eddie4.nl:6969 
[1] 12380
[2] 12381
[3] 12382
[4] 12383
[5] 12384
[6] 12385
$ Unexpected response: <h1> 401: Unauthorized</h1> Unauthorized User
Unexpected response: <h1> 401: Unauthorized</h1>Unauthorized User
All-In-One: command not found
^C
[1]   Exit 1                  sudo transmission-remote --download-dir "/home/ubuntu/Downloads" -a magnet:?xt=urn:btih:2c83f573753d9e987a5bf0fcf8979c4aa137e869
[2]   Exit 127                dn=Linux All-In-One For Dummies, 6th Edition
[3]   Done                    tr=udp://tracker.leechers-paradise.org:6969
[4]   Done                    tr=udp://tracker.coppersurfer.tk:6969
[5]-  Done                    tr=udp://tracker.opentrackr.org:1337
[6]+  Done                    tr=udp://tracker.pirateparty.gr:6969
Service has username and password defined in settings file.
"rpc-password": "{95a4599e6748c68a07fbdfb7a49e37cb27d1c9b8NjXpGV6G",
"rpc-username": "transmission",
Default username and password: transmission
To use remote commands we need to add auth parameter.
Start torrent again.
$ transmission-remote --auth transmission:transmission --download-dir "/home/ubuntu/Downloads" -a magnet:?xt=urn:btih:2c83f573753d9e987a5bf0fcf8979c4aa137e869&dn=Linux All-In-One For Dummies, 6th Edition&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.opentrackr.org:1337&tr=udp://tracker.pirateparty.gr:6969&tr=udp://eddie4.nl:6969 
[1] 12422
[2] 12423
[3] 12424
[4] 12425
[5] 12426
[6] 12427
$ localhost:9091/transmission/rpc/ responded: "success"
localhost:9091/transmission/rpc/ responded: "success"
All-In-One: command not found

[1]   Done                    transmission-remote --auth transmission:transmission --download-dir "/home/ubuntu/Downloads" -a magnet:?xt=urn:btih:2c83f573753d9e987a5bf0fcf8979c4aa137e869
[2]   Exit 127                dn=Linux All-In-One For Dummies, 6th Edition
[3]   Done                    tr=udp://tracker.leechers-paradise.org:6969
[4]   Done                    tr=udp://tracker.coppersurfer.tk:6969
[5]-  Done                    tr=udp://tracker.opentrackr.org:1337
[6]+  Done                    tr=udp://tracker.pirateparty.gr:6969
$ transmission-remote -l
Unexpected response: <h1> 401: Unauthorized</h1>Unauthorized User
Check torrent status.
$ transmission-remote --auth transmission:transmission -l
ID     Done       Have  ETA           Up    Down  Ratio  Status       Name
   1    n/a       None  Unknown      0.0     0.0   None  Idle         2c83f573753d9e987a5bf0fcf8979c4aa137e869
Sum:              None               0.0     0.0

Error#3: Couldn't create folder


Check service status.
$ sudo service transmission-daemon status
● transmission-daemon.service - Transmission BitTorrent Daemon
   Loaded: loaded (/lib/systemd/system/transmission-daemon.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-07-29 13:06:31 UTC; 20min ago
  Process: 12279 ExecStop=/bin/kill -s STOP $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 12324 (transmission-da)
   Status: "Idle."
    Tasks: 3 (limit: 1152)
   CGroup: /system.slice/transmission-daemon.service
           └─12324 /usr/bin/transmission-daemon -f --log-error

Jul 29 13:17:12 ip-172 transmission-daemon[12324]: [2018-07-29 13:17:12.138] Couldn't create "/home/ubuntu/Downloads/Linux All-In-One For
...
We need to give some permissions
$ sudo usermod -a -G debian-transmission ubuntu

$ sudo chgrp -R debian-transmission /home/ubuntu/Downloads/

$ sudo chmod -R 775 /home/ubuntu/Downloads/
Before starting torrent again, check torrent.
$ transmission-remote --auth transmission:transmission -l
ID     Done       Have  ETA           Up    Down  Ratio  Status       Name
   1*    0%   49.15 kB  Unknown      0.0     0.0    0.0  Stopped      Linux All-In-One For Dummies, 6th Edition
Sum:          49.15 kB               0.0     0.0
We can remove a torrent from the list.
$ sudo transmission-remote --auth transmission:transmission -t 1 -r
localhost:9091/transmission/rpc/ responded: "success"
$ transmission-remote --auth transmission:transmission -l
ID     Done       Have  ETA           Up    Down  Ratio  Status       Name
Sum:              None               0.0     0.0
Start torrent again and watch for status.
$ transmission-remote --auth transmission:transmission --download-dir "/home/ubuntu/Downloads" -a magnet:?xt=urn:btih:2c83f573753d9e987a5bf0fcf8979c4aa137e869&dn=Linux All-In-One For Dummies, 6th Edition&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.opentrackr.org:1337&tr=udp://tracker.pirateparty.gr:6969&tr=udp://eddie4.nl:6969 
[1] 12563
[2] 12564
[3] 12565
[4] 12566
[5] 12567
[6] 12568
$ localhost:9091/transmission/rpc/ responded: "success"
localhost:9091/transmission/rpc/ responded: "success"
All-In-One: command not found

[1]   Done                    transmission-remote --auth transmission:transmission --download-dir "/home/ubuntu/Downloads" -a magnet:?xt=urn:btih:2c83f573753d9e987a5bf0fcf8979c4aa137e869
[2]   Exit 127                dn=Linux All-In-One For Dummies, 6th Edition
[3]   Done                    tr=udp://tracker.leechers-paradise.org:6969
[4]   Done                    tr=udp://tracker.coppersurfer.tk:6969
[5]-  Done                    tr=udp://tracker.opentrackr.org:1337
[6]+  Done                    tr=udp://tracker.pirateparty.gr:6969
$ transmission-remote --auth transmission:transmission -l
ID     Done       Have  ETA           Up    Down  Ratio  Status       Name
   2     0%       None  Unknown      0.0     0.0   None  Idle         Linux All-In-One For Dummies, 6th Edition
Sum:              None               0.0     0.0
$ transmission-remote --auth transmission:transmission -l
ID     Done       Have  ETA           Up    Down  Ratio  Status       Name
   2     3%   507.9 kB  4 min        0.0   258.0    0.0  Downloading  Linux All-In-One For Dummies, 6th Edition
Sum:          507.9 kB               0.0   258.0
$ transmission-remote --auth transmission:transmission -l
ID     Done       Have  ETA           Up    Down  Ratio  Status       Name
   2   100%   13.37 MB  Done         0.0     0.0    0.0  Idle         Linux All-In-One For Dummies, 6th Edition
Sum:          13.37 MB               0.0     0.0