How To Install And Use Tor (Client) As A Proxy In Ubuntu, Pop!_OS Or Linux Mint
Tor (The Onion Router) directs Internet traffic through a volunteer overlay network, with the purpose of protecting the user's privacy and freedom.
This article explains how to install the latest Tor Client in Ubuntu 20.10, 20.04, 19.10, 18.04 or 16.04 / Linux Mint 20, 19.x and 18.x, and using it as a proxy with various applications.
The instructions below include steps for setting up Privoxy, in case you want to use Tor with an application that doesn't support SOCKS5 proxies, manually setting up the proxy in case torsocks fails to launch an application, as well as configuring Tor to use country-specific exit nodes (so you can specify from which country your new IP should be), useful if you want to bypass country restrictions / censorship and you don't afford a VPN (but if you can, go for the VPN option!).
This should work in Ubuntu 16.04 / Linux Mint 18.x, Ubuntu 18.04 / Linux Mint 19.x, 19.10 and 20.04 / Linux Mint 20, Ubuntu 20.10 and newer, as well as Linux distributions based on Ubuntu, like Pop!_OS, elementary OS, and Ubuntu or Linux Mint flavors, like Linux Mint MATE or Kubuntu, Xubuntu, Ubuntu MATE, and so on.
Ubuntu versions older than 16.04 / Linux Mint older than 18.x don't use systemd, so some things in this article won't work for such old versions.
Tor does not prevent online services from determining that you're using Tor so keep this in mind! This should be used for privacy, and not anonymity. If all you need a web browser using Tor, use Tor Browser which uses Firefox ESR as its base, is very easy to use, and it includes everything you need. This article is for using the Tor client with other applications. Do not confuse Tor (client) with Tor Browser, they are two different things (in what they do)!
Installing Tor and optionally Privoxy in Ubuntu / Pop!_OS or Linux Mint
I. Install Tor in Ubuntu / Pop!_OS or Linux Mint
The Tor package from the Ubuntu repositories is usually not updated frequently, so it's recommended you use the official Tor repository instead.
Start by installing
apt-transport-https
, needed in order to use https repositories, and curl, to download the repository key:sudo apt install apt-transport-https curl
And then add the Tor repository (and its key) in Ubuntu / Pop!_OS using these commands:
sudo -i
echo "deb https://deb.torproject.org/torproject.org/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/tor.list
curl https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --import
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | apt-key add -
apt update
exit
For Linux Mint, use the same commands as above, but replace
$(lsb_release -cs)
in the first command with the Ubuntu version codename your Linux Mint version is based on. For Linux Mint 20 use focal
, for Linux Mint 19 (and 19.x) use bionic
, while for Linux Mint 18.x use xenial
.Now you can install Tor,
tor-geoipdb
(to be able to use country specific exit nodes), torsocks
(a library to easily torify applications) and deb.torproject.org-keyring
(a package that makes sure you have the latest repository signing key):sudo apt install tor tor-geoipdb torsocks deb.torproject.org-keyring
II. Optionally install Privoxy and configure it for use with Tor
Privoxy is a non-caching web proxy. You can use it with Tor if you plan on using Tor with applications that only support HTTP proxies (don't support SOCKS5 proxies).
To install Privoxy in Ubuntu / Pop!_OS or Linux Mint, use:
sudo apt install privoxy
To use Privoxy with Tor you'll need to edit its
/etc/privoxy/config
configuration file with a text editor, like Nano (as root):sudo nano /etc/privoxy/config
In this configuration file, paste the following line at the end of the file (you can get to the end of the file with Nano command line text editor by pressing
Ctrl + W
followed by Ctrl + V
, without changing anything else:forward-socks5 / localhost:9050 .
There's a space and then a dot at the end of the line, that is not a typo.
Then save the file and exit (to save the file using Nano command line text editor, press
Ctrl + O
, then Enter
; exit using Ctrl + X
).Now you'll need to restart Privoxy:
sudo systemctl restart privoxy
Using Tor and Privoxy in Ubuntu / Pop!_OS or Linux Mint
I. Using Tor via torsocks
To easily launch an application and make it use Tor, you can use
torsocks
, which works with both GUI and command line programs. This library ensures that DNS requests are handled safely and explicitly rejects any traffic other than TCP from the application you're using.For example, to launch Spotify with torsocks, use:
torsocks spotify
To test it, run this command to get your real IP address:
curl ipv4.icanhazip.com
(In case
curl
is not installed, you can install it using: sudo apt install curl
)And then run the same command but using torsocks:
torsocks curl ipv4.icanhazip.com
The torsocks command should return a different IP because it was ran through the Tor proxy.
If you get an error, the Tor service may not be running. It should be automatically started when it's installed, but in case it's not, you can start it using this command:
sudo systemctl start tor
There is a problem with torsocks though - it fails to launch some applications. For example, running
torsocks firefox
or torsocks google-chrome
does nothing. For such cases, you'll need to enter the Tor SOCKS5 proxy manually in the application you want to use - see below.II. Enter the proxy address manually
Once you install Tor and Privoxy, you can use the following proxy information (you only need to set up one of these two) in the application network / proxy settings:
- SOCKS5 proxy: use
localhost
as the proxy host / IP, and9050
as the port - HTTP proxy (requires Privoxy installed and configured as explained): use
localhost
as the proxy address and8118
as the port
Use a SOCKS5 proxy where possible or, if the application doesn't support it, use a regular HTTP proxy instead.
You can also use Tor as a system-wide proxy. For example in Gnome go to
System Settings > Network
, click on Network Proxy
, set the proxy to Manual
, then use localhost
as the Socks Host and 9050
as the port:Note that Chromium-based web browsers (Google Chrome, Opera, Vivaldi, etc.) don't allow setting a proxy in their settings and instead use the system-wide proxy.
III. How to change the IP address given by Tor
In case you need to change the IP address given by Tor, the easiest way is to reload the Tor service, like this:
sudo systemctl reload tor
This command will reload the Tor configuration and get Tor to set up a new circuit, giving you a new IP address.
Check the IP address using the
torsocks curl ipv4.icanhazip.com
command.IV. How to configure Tor to use country specific exit nodes (choose from which country your new IP should be)
To be able to specify country specific exit nodes in Tor, the
tor-geoipdb
package needs to be installed. This package is mentioned in the instructions above, so it should already be installed, but I thought I'd mention this in case you already had Tor installed and skipped the installation instructions from this article.To use Tor to change your IP to a specific country IP, you'll need to edit the Tor
/etc/tor/torrc
configuration file as root:sudo nano /etc/tor/torrc
Add the following two lines to the file, without changing anything else:
ExitNodes {COUNTRY_CODE}
StrictNodes 1
Replace
COUNTRY_CODE
with the 2 letter ISO3166 country code, for example use us
for the United States, de
for Germany, and so on. You can find a list of country codes here. You can also specify multiple countries by separating them with a comma, like this: {country1},{country2},{country3}
, for example {be},{pl},{ca}
. The countries need to be specified between curly brackets: {}
.When you're done, save the file and exit (to save the file using Nano command line text editor, press
Ctrl + O
, then Enter
; exit using Ctrl + X
), and reload the Tor configuration using this command:sudo systemctl reload tor