Skip to content

Instantly share code, notes, and snippets.

@maximousblk
Created September 8, 2020 06:29
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save maximousblk/2f7cb476a528e23a717093cd9cd22560 to your computer and use it in GitHub Desktop.
Save maximousblk/2f7cb476a528e23a717093cd9cd22560 to your computer and use it in GitHub Desktop.
A super simple guide to starting up your own Tor hidden service

Host your own Tor hidden service!

A super simple guide to spinning up a Tor hidden service. [tl;dr]

Ubuntu 20.04 LTS was used for the making of this guide.

Install Tor

you can install Tor using the following command

sudo apt install torbrowser-launcher

This package includes everything you need to run a Tor hidden service and to browse them.

If you're running this on a server and don't need the browser, you can install the standalone Tor daemon using the following command

sudo apt install tor

Config

you need to look for a torrc file which will most probably be in the /etc/tor directory. open it in an editor. you'll need to use sudo because it is a protected file.

#nano
sudo nano /etc/tor/torrc

#vim
sudo vim /etc/tor/torrc

Look for the following lines.

############### This section is just for location-hidden services ###

## Once you have configured a hidden service, you can look at the
## contents of the file ".../hidden_service/hostname" for the address
## to tell people.
##
## HiddenServicePort x y:z says to redirect requests on port x to the
## address y:z.

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

you need to uncomment these lines and update accordingly

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

Where PORT is the port number on which your application is accessible on the localhost.

For this guide, we're going to use a simple directory listing server.

If you have NodeJS installed, you can use the following command to start the server.

npx serve -l 5000

Alternatively, if you have Python 3 installed, you can use the following command to start a python http server.

python3 -m http.server --bind 127.0.0.1 5000

So our torrc file now looks like following

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

Start Tor

Now that everything is configured, you can start the Tor service by using the following command.

sudo tor

Upon starting tor for the first time, a new .onion address will be generated for you. you can get the address using the following command

sudo cat /var/lib/tor/hidden_service/hostname

If you've changed the HiddenServiceDir setting in the torrc file, you can find the hostname in <HiddenServiceDir>/hostname file.

Anyone can now visit this address using Tor Browser to use your website.

tl;dr

This is a pretty short guide though. But anyways...

Install Tor

sudo apt install tor

Config

echo -e "HiddenServiceDir /var/lib/tor/hidden_service/\nHiddenServicePort 80 127.0.0.1:5000" | sudo tee -a /etc/tor/torrc

Start server

# NodeJS
npx serve -l 5000

# Python 3
python3 -m http.server --bind 127.0.0.1 5000

Start Tor

sudo tor

Get hostname

sudo cat /var/lib/tor/hidden_service/hostname

And just like that, your web app is deployed on Tor. Now get off my lawn ι(`ロ´)ノ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment