Creating a hidden service is a good way to get introduced to tor and onion routing. For this walk through, I will be installing tor on Ubuntu 18.04 LTS and be using nginx as my web server. This is for educational purposes only. What you do on your hidden service is your responsibility.
sudo apt install nginx
To get the tor binaries you can either install from the tor repositories or you can download and build it from source. In this, I will be installing it via the repositories because it is quicker and easier.
echo deb https://deb.torproject.org/torproject.org bionic main | sudo tee /etc/apt/sources.list.d/tor.list
echo deb-src https://deb.torproject.org/torproject.org bionic main | sudo tee -a /etc/apt/sources.list.d/tor.list
- The -a in the second tee command means that it will append rather than overwrite.
gpg2 --recv A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD8
gpg2 --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
sudo apt-get update && sudo apt-get install tor deb.torproject.org-keyring
Now tor and nginx are installed and we just have to configure them.
- Make web root. This is where your web files will go.
sudo mkdir -p /var/www/onionsite/
- Nginx config server file.
- You want to make a simple nginx config file in the /etc/nginx/sites-available/tor.
- My file is
- Link Nginx config.
sudo ln -s /etc/nginx/sites-available/tor /etc/nginx/sites-enabled/
- Use the full path when linking otherwise it can break.
The default tor config is located at /etc/tor/torrc. I would recommend backing up the current one you have and starting fresh. You want a config that contains:
- You can omit this line if you want to run an onion v2 hidden service.
HiddenServicePort 80 127.0.0.1:445
Mine looks like
And you now have a hidden service configure. Just restart all services with
sudo systemctl restart nginx and
sudo systemctl restart tor. Your hidden service address will be generated in /var/lib/tor/onion/hostname/.
Enjoy your hidden service web site.