I read on many tutorials and websites that Tor will generate the hostname for you and put in a certain file, however it is not doing it and when I asked why, someone replied saying that is not what happens but that you need to create and configure it yourself. How do I do this?
Assuming the program that generated the hostname for you is working properly, it should give you 2 files, once called
hostname and the other called
private_key. Put the 2 files in one folder, for example
/home/user/tor_private. The next step is to add a reference to this folder in your torrc file. Open your torrc file (it is in
/etc/tor/torrc when you use some sort of GNU/Linux), and add the following two lines at the end of the file:
HiddenServiceDir /home/user/tor_private HiddenServicePort 80 127.0.0.1:80
Finally, don't forget to tell your webserver (e.g. apache2) about the folder where you are putting your website files (your HTML files). Then, you'll have to restart Tor, and your webserver (e.g. apache2) afterwards, and your site will become accessible from the Tor network. The onion address of your website can be found in the
hostname file you've put in
Few recommendations you should be aware of:
- For security reasons, it is not advised to run Tor using the root user. Instead create a user for Tor. Some Linux distros such as Debian automatically create a user called
debian-torwhen you install the Tor package. Use the Tor user (you created or already created by the system) to run Tor.
Make sure only root or the Tor user have read access on the folder
/home/user/tor_private. So the permissions on the folder should be 700.
Don't put your website files inside
/home/user/tor_private. That folder is only for storing your private key. Put them somewhere else accessible by the webserver.
Don't share the
private_keyfile with anybody. If anybody gets his hand on this file, you can take over your onion address and you'll loose ownership to your site!