Install tor on debian 9 stretch

Add to source:
/etc/apt/sources.list.d/tor.list:

deb http://deb.torproject.org/torproject.org stretch main
deb-src http://deb.torproject.org/torproject.org stretch main

Now install keys and tor:

gpg --keyserver keys.gnupg.net --recv A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
apt-get install tor deb.torproject.org-keyring

Add backports repo.
Create /etc/apt/sources.list.d/backports:
deb http://httpredir.debian.org/debian jessie-backports main contrib non-free
Now update apt cache:
sudo apt-get update
So that failed
Installing from source:
apt-get install libevent-dev
wget https://www.torproject.org/dist/tor-0.3.0.8.tar.gz
tar xvf tor-0.3.0.8.tar.gz
cd tor-0.3.0.8


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

tor: generate new hashed password

tor --hash-password newpassword
16:8AAFE154916DD5E86098C741C81FFD4769FC270942315E9ADCC8D00701

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

What’s the onion address of the piratebay?

The onion address of the piratebay on the darknet is http://uj3wazyk5u4hnvtk.onion. Of course, you need the tor browser to access it. Use it if your ISP blocks piratebay proxies. In fact most proxies are nowdays riddled with ads. The original piratebay doesnt, so you can use tor if you hate ads.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

How to create a personal piratebay proxy

You need a VPS. Boot it up, login as root:
cd /root
apt-get install libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev gcc make git socat screen
wget http://nginx.org/download/nginx-1.11.13.tar.gz
tar xvf nginx-1.11.13.tar.gz
git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
tar xzvf nginx-nginx-1.10.3.tar.gz
cd ~/nginx-1.11.13
./configure –with-http_ssl_module –add-module=~/ngx_http_substitutions_filter_module
make && make install
cd /usr/local/nginx/
./sbin/nginx

Test by going to the ip address of host.

cd /usr/local/nginx/conf
mv nginx.conf nginx.conf-backup
emacs nginx.conf

Add the code:

worker_processes auto;
events {
  worker_connections 1024;
}
http {
  include  mime.types;
  default_type application/octet-stream;
  sendfile on;
  gzip on;
  server {
    listen 80;
    server_name server_ip;

    location / {
    proxy_pass http://127.0.0.1:81/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
	}
  }
}

Start nginx after stopping it:

/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx

Create a daemon:

emacs ~/socat.sh
#!/bin/bash
socat tcp4-LISTEN:81,reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:127.0.0.1:uj3wazyk5u4hnvtk.onion:80,socksport=9050

Run the daemon

screen -A -m -d -S SOCAT_DAEMON ~/socat.sh

To start it at boot, add to /etc/rc.local

/username/socat.sh

Enjoy

Credits:
1. https://proxybay.one/setup.html
2. http://tor.stackexchange.com/questions/13792/how-can-i-nginx-reverse-proxy-to-onion-site-which-is-on-tor-network/13884


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Download youtube video on the command line

The program you need is youtube-dl

Install youtube-dl:
Get the latest version install instructions here

Eg:

sudo curl https://yt-dl.org/downloads/2016.05.16/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

Update to latest version:

youtube-dl -U

Sometimes youtube blocks downloads.
Eg:
#youtube-dl -F https://www.youtube.com/watch?v=r3fhuJJRcYc
[youtube] r3fhuJJRcYc: Downloading webpage
ERROR: Unable to download webpage: HTTP Error 429: Too Many Requests (caused by HTTPError()); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type youtube-dl -U to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

In this case, your ip is being blocked by Google. Use tor to mask your ip:
#torify youtube-dl -F https://www.youtube.com/watch?v=r3fhuJJRcYc
[youtube] r3fhuJJRcYc: Downloading webpage
[youtube] r3fhuJJRcYc: Downloading video info webpage
[youtube] r3fhuJJRcYc: Extracting video information
[youtube] r3fhuJJRcYc: Downloading js player en_US-vflGdEImZ
[info] Available formats for r3fhuJJRcYc:
format code extension resolution note
249 webm audio only DASH audio 54k , opus @ 50k, 1.80MiB
250 webm audio only DASH audio 77k , opus @ 70k, 2.43MiB
140 m4a audio only DASH audio 128k , m4a_dash container, [email protected], 4.45MiB
251 webm audio only DASH audio 149k , opus @160k, 4.75MiB
171 webm audio only DASH audio 150k , [email protected], 4.55MiB
278 webm 256x144 144p 111k , webm container, vp9, 12fps, video only, 3.26MiB
160 mp4 256x144 144p 111k , avc1.4d400c, 24fps, video only, 3.84MiB
133 mp4 426x240 240p 252k , avc1.4d4015, 24fps, video only, 8.62MiB
242 webm 426x240 240p 256k , vp9, 24fps, video only, 7.19MiB
243 webm 640x360 360p 472k , vp9, 24fps, video only, 13.00MiB
134 mp4 640x360 360p 638k , avc1.4d401e, 24fps, video only, 13.03MiB
244 webm 854x480 480p 822k , vp9, 24fps, video only, 22.17MiB
135 mp4 854x480 480p 1166k , avc1.4d401e, 24fps, video only, 25.19MiB
247 webm 1280x720 720p 1566k , vp9, 24fps, video only, 41.77MiB
136 mp4 1280x720 720p 2288k , avc1.4d401f, 24fps, video only, 44.77MiB
248 webm 1920x1080 1080p 2715k , vp9, 24fps, video only, 73.14MiB
137 mp4 1920x1080 1080p 3726k , avc1.640028, 24fps, video only, 77.35MiB
17 3gp 176x144 small , mp4v.20.3, mp4a.40.2@ 24k
36 3gp 320x180 small , mp4v.20.3, mp4a.40.2
5 flv 426x240 small , h263, mp3 @ 64k
43 webm 640x360 medium , vp8.0, [email protected]
18 mp4 640x360 medium , avc1.42001E, mp4a.40.2@ 96k
22 mp4 1280x720 hd720 , avc1.64001F, [email protected] (best)

Downloading mp3 songs from youtube video:

torify youtube-dl --extract-audio --audio-format mp3 https://www.youtube.com/watch?v=APJxwxZuA0E

Use a bash alias to simplify the process:

alias ymp3='torify youtube-dl --extract-audio --audio-format mp3'
ymp3 https://www.youtube.com/watch?v=Qs2ta9_CaKM

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Use tor for any command on Linux

The following details a procedure to use tor for any commands used on the command line in Linux. The test env here is a Debian server.

Install tor:

# apt-get install tor

You should create a hashed control password for tor:

#tor --hash-password 'mypassword'
Apr 22 21:00:14.198 [notice] Tor v0.2.4.27 (git-412e3f7dc9c6c01a) running on Linux with Libevent 2.0.19-stable and OpenSSL 1.0.1e.
Apr 22 21:00:14.198 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Apr 22 21:00:14.206 [warn] You are running Tor as root. You don't need to, and you probably shouldn't.
16:A08B4CD129C38494608095E8CB6E3CF6FD61987221130F81E49F28783D

Now setup tor options in the control file at /etc/tor/torrc so that it contains the following:

ControlPort 9051
CookieAuthentication 0
HashedControlPassword 16:A08B4CD129C38494608095E8CB6E3CF6FD61987221130F81E49F28783D

Now, Restart the tor service:

service tor restart

Test the current ip:
# curl ifconfig.me 2>/dev/null
196.152.33.228

Now test the torrized ip:

# torify curl ifconfig.me 2>/dev/null
162.247.72.212

To get a new ip, do this:

echo -e 'AUTHENTICATE "mypassword"\r\nsignal NEWNYM\r\nQUIT' | nc 127.0.0.1 9051

Here, you’re providing the password which you created earlier.

Test the new ip:

# torify curl ifconfig.me 2>/dev/null
77.109.141.138

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.