Most of you are familiar with Tor, a free and open-source software for enabling anonymous communication, in this guide we will learn how to quickly and easily create a Tor hidden service on an Ubuntu or Debian linux based server. 

 

Requirements

  • An Ubuntu or Debian linux based server
  • 5 Minutes of your time

Step 1.

For the purpose of this guide I will be installing Tor on Ubuntu 20.04, so I will skip this step however if you are on Debian please continue Step 1 –

Edit /etc/apt/sources.list and add the following lines to the file:

deb-src http://nginx.org/packages/debian/ wheezy nginx
deb http://nginx.org/packages/debian/ wheezy nginx
deb http://deb.torproject.org/torproject.org wheezy main

And import the GPG keys to sign with by running the following commands:

gpg —keyserver keys.gnupg.net —recv 886DDD89
gpg —export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
wget http://nginx.org/keys/nginx_signing.key 
apt-key add nginx_signing.key

Some users may experience problems by running the command gpg —keyserver keys.gnupg.net —recv 886DDD89 if this happens to be the case for you, try using the curl method as follows:

curl https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --import

Step 2.

Now it’s time to update the sources with the ones we added in step 1 by running the following command:

sudo apt-get update

Now we are ready to install Tor and nginx (our webserver) by running the following command:

apt-get install nginx tor

Step 3.

First let’s configure Tor by editing Tor’s configuration file located at /etc/tor/torrc and add these two lines at the bottom:

HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 80 127.0.0.1:8080

Create the HiddenServiceDirectory and give it appropriate permissions by running the following commands:

mkdir /var/lib/tor/hidden_service/ 
chown debian-tor:debian-tor /var/lib/tor/hidden_service/ 
chmod 0700 /var/lib/tor/hidden_service/

To configure nginx to work with our Tor instance we will create or edit the file /etc/nginx/conf.d/default.conf and use the following configuration:

server {
listen 127.0.0.1:8080;
root /var/www/tor;
client_max_body_size 100M;
charset utf-8;
index index.html;
}

Now let’s create the website directory and default index.html file:

mkdir /var/www/tor

Paste the following inside of index.html as a place holder (/var/www/tor/index.html):

<b>Tor Hidden Service is online!<b>

Restart the Tor & nginx service:

/etc/init.d/nginx restart
/etc/init.d/tor restart

Step 4.

Let’s get our .onion URL from the file /var/lib/tor/hidden_service/hostname with the following command:

cat /var/lib/tor/hidden_service/hostname

You have just successfully set up your Tor hidden serivce. You will be able to use this onion URL as soon as it propagates over the tor network (it can take a few minutes at times).