Make tor configuration directory:
$> mkdir -p ~/configuration_files/tor
$> config=~/configuration_files/tor
$> cd "${config}"
Copy /etc/tor/torrc to the configuration directory and make as many copies as you need: for example. 10
printf "torrc_%0.2s\n" {1..10} | xargs -I {} /bin/cp /etc/tor/torrc "${config}{}"
Copy /etc/torsocks.conf to the configuration directory and make as many copies as you need: for example. same as above 10
printf "torsocks_%0.2s.conf\n" {1..10} | xargs -I {} /bin/cp /etc/torsocks.conf "${config}/{}"
Create new data directories and correct ownership / permissions:
$> sudo mkdir /var/lib/tor{1..10}
Edit the configuration files so that they do not interfere with the corresponding port numbers:
for a in {1..10}; do sed -i "s/^#SocksPort 9050.*/SocksPort $((9050+${i}))/;s|^#DataDirectory /var/lib/tor|DataDirectory /var/lib/tor${i}|" torrc_${i} sed -i "s/server_port = 9050/server_port = $((9050+${i}))/" torsocks_${i}.conf sudo chmod -R --reference /var/lib/tor /var/lib/tor${i} sudo chown -R CHANGETHIS:CHANGETHIS /var/lib/tor${i} done
Note. Change CHANGETHIS to the user / group of the user who plans to use it.
After that, it is easy to get it; you start separate instances of tor using the corresponding configuration file, for example. /usr/bin/tor -f "${config}/torrc_3"
To use it all you have to do is export the TORSOCKS_CONF_FILE variable to point to the corresponding torsocks.conf file:
For example. $> export TORSOCKS_CONF_FILE="${config}/torsocks_3.conf"
Then you can torify / torsocks any application from this particular shell, and it will use the torsocks_3.conf proxy server.
Try: $> torify bash
$> curl www.ipmango.com/api/myip
To switch to another proxy, simply run the corresponding tor using its torrc file and export the TORSOCKS_CONF_FILE variable to indicate the new configuration.
Here is a simple alias that does the job after you configured it above and you have roxterm installed. It will check netstat to make sure that the proxy server is already running, and if it does not start in a separate shell window.
alias prox='_(){ proxy=${1:-1}; config_base="~/configuration_files/tor"; port=$((9050+${proxy})); netstat -an | { ! grep -q "127.0.0.1:${port}"; } && roxterm -e bash -c "/usr/bin/tor -f \"${config_base}/torrc_${proxy}\"; bash"; export TORSOCKS_CONF_FILE="${config_base}/torsocks_${proxy}.conf"; }; _'
To use it:
$> prox 4 $> torify bash
user4401178 Dec 10 '15 at 23:45 2015-12-10 23:45
source share