How to host a Tor hidden service
A super simple guide to running up a Tor hidden service.
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.