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
Apr 22 21:00:14.206 [warn] You are running Tor as root. You don't need to, and you probably shouldn't.

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 2>/dev/null

Now test the torrized ip:

# torify curl 2>/dev/null

To get a new ip, do this:

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

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

Test the new ip:

# torify curl 2>/dev/null