Use tor for any command on Linux

The following details a procedure to use tor for any commands used on the command line in Linux. The test env here is a Debian server.

Install tor:

# apt-get install tor

You should create a hashed control password for tor:

#tor --hash-password 'mypassword'
Apr 22 21:00:14.198 [notice] Tor v0.2.4.27 (git-412e3f7dc9c6c01a) running on Linux with Libevent 2.0.19-stable and OpenSSL 1.0.1e.
Apr 22 21:00:14.198 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Apr 22 21:00:14.206 [warn] You are running Tor as root. You don't need to, and you probably shouldn't.
16:A08B4CD129C38494608095E8CB6E3CF6FD61987221130F81E49F28783D

Now setup tor options in the control file at /etc/tor/torrc so that it contains the following:

ControlPort 9051
CookieAuthentication 0
HashedControlPassword 16:A08B4CD129C38494608095E8CB6E3CF6FD61987221130F81E49F28783D

Now, Restart the tor service:

service tor restart

Test the current ip:
# curl ifconfig.me 2>/dev/null
196.152.33.228

Now test the torrized ip:

# torify curl ifconfig.me 2>/dev/null
162.247.72.212

To get a new ip, do this:

echo -e 'AUTHENTICATE "mypassword"\r\nsignal NEWNYM\r\nQUIT' | nc 127.0.0.1 9051

Here, you’re providing the password which you created earlier.

Test the new ip:

# torify curl ifconfig.me 2>/dev/null
77.109.141.138

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.