Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

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

Jul 31, 2018

Ubuntu torrent client - Transmission-cli

If you need a torrent client on Ubuntu server you can use transmission package. This tutorial explains only command line interface.

Install
sudo apt-get install transmission-cli
Cli package has no setting file! You have to give settings with parameters.

Get help
$ transmission-cli --help
transmission-cli 2.92 (14714)
A fast and easy BitTorrent client

Usage: transmission-cli [options] <file|url|magnet>

Options:
 -h  --help                          Display this help page and exit
 -b  --blocklist                     Enable peer blocklists
 -B  --no-blocklist                  Disable peer blocklists
 -d  --downlimit            <speed>  Set max download speed in kB/s
 -D  --no-downlimit                  Don't limit the download speed
 -er --encryption-required           Encrypt all peer connections
 -ep --encryption-preferred          Prefer encrypted peer connections
 -et --encryption-tolerated          Prefer unencrypted peer connections
 -f  --finish               <script> Run a script when the torrent finishes
 -g  --config-dir           <path>   Where to find configuration files
 -m  --portmap                       Enable portmapping via NAT-PMP or UPnP
 -M  --no-portmap                    Disable portmapping
 -p  --port                 <port>   Port for incoming peers (Default: 51413)
 -t  --tos                  <tos>    Peer socket TOS (0 to 255,
                                     default=default)
 -u  --uplimit              <speed>  Set max upload speed in kB/s
 -U  --no-uplimit                    Don't limit the upload speed
 -v  --verify                        Verify the specified torrent
 -V  --version                       Show version number and exit
 -w  --download-dir         <path>   Where to save downloaded data
Usage: transmission-cli [options]
Download a torrent with download directory parameter.
sudo transmission-cli  http://torrent.ubuntu.com:6969/file?info_hash=D%C0%809M3%5B%03%0B%13%FA%F1%3F%A8%84%CD%22%15%028 --download-dir "/home/ubuntu/Downloads"
You can use magnet link instead of torrent file url.
If you are using AWS or any firewall, don't forget to give permission for "Port for incoming peers (Default: 51413)"
After download finishes you will see transmission will continue to run for seeding. It may be annoying if you are working on terminal because it interrupts terminal window (even you press to Ctrl-C to quit).
To kill the process type ps to see process id.
  PID TTY          TIME CMD
11659 pts/0    00:00:00 sudo
11668 pts/0    00:00:00 transmission-cl
Then kill process.
$ kill 11668

Jul 29, 2018

Linux commands - Process

List running processes
$ ps -A
  PID TTY          TIME CMD
    1 ?        00:00:03 systemd
    2 ?        00:00:00 kthreadd
    4 ?        00:00:00 kworker/0:0H
    6 ?        00:00:00 mm_percpu_wq
    7 ?        00:00:00 ksoftirqd/0
    8 ?        00:00:00 rcu_sched
    9 ?        00:00:00 rcu_bh
   10 ?        00:00:00 migration/0
   11 ?        00:00:00 watchdog/0
   12 ?        00:00:00 cpuhp/0
 4712 ?        00:00:00 nginx
Kill a process
$ kill [signal] PID(s)

$ kill -9 3139

Signal Name  Signal Value  Behaviour
SIGHUP   1   Hangup
SIGKILL   9   Kill Signal
SIGTERM   15   Terminate
Filter process by name
$ ps aux | grep nginx

root      4712  0.0  0.1 140644  1452 ?        Ss   Jul27   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data  4714  0.0  0.4 143260  4212 ?        S    Jul27   0:00 nginx: worker process
ubuntu   11494  0.0  0.1  14856  1056 pts/0    S+   10:50   0:00 grep --color=auto nginx

$ pgrep nginx

4712
4714
Kill process by name
$ pkill nginx

$ killall nginx