A script to quickly set up Tor

Requirements

Debian 7 (Wheezy), 8 (Jessie) or 9 (Stretch).

Usage

curl https://romanrm.net/_export/code/tor?codeblock=3 -o setup-tor.sh
chmod +x setup-tor.sh
./setup-tor.sh Nickname DirPort ORPort

If you don't have a web server on the same machine, use DirPort 80 and ORPort 443, i.e.:

./setup-tor.sh MyTorRelayName 80 443

The relay name length is limited to 18 characters or so.

You can also run the script as

./setup-tor.sh off

to completely remove Tor.

Script

setup-tor.sh
#!/bin/bash
 
if [ "$1" == "off" ]; then
  dpkg -P deb.torproject.org-keyring tor tor-arm tor-geoipdb
  apt-get autoremove
  rm -rvf /etc/tor/ /etc/tor2/ /var/lib/tor/ /var/lib/tor2/ /etc/init.d/tor /etc/init.d/tor2 2> /dev/null
  rm /etc/apt/sources.list.d/tor.list
  apt-get update
  exit 0
fi
 
echo -n "Debian release: "
if   grep ^9 /etc/debian_version; then
  RELEASE=stretch;
elif grep ^8 /etc/debian_version; then
  RELEASE=jessie;
elif grep ^7 /etc/debian_version; then
  RELEASE=wheezy;
else
  echo Unknown!
  exit 1
fi
 
NICKNAME=$1
DIRPORT=$2
ORPORT=$3
 
if [ "$DIRPORT" == "" ]||[ "$ORPORT" == "" ]; then
  echo Usage: setup-tor.sh Nickname DirPort ORPort
  exit 1
fi
 
echo "deb http://deb.torproject.org/torproject.org $RELEASE main" > /etc/apt/sources.list.d/tor.list
 
gpg --keyserver keys.gnupg.net --recv 886DDD89
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | apt-key add -
 
apt-get update
apt-get install -y deb.torproject.org-keyring tor tor-arm
 
echo "DisableDebuggerAttachment 0" >  /etc/tor/torrc
echo "Nickname $NICKNAME"          >> /etc/tor/torrc
echo "DirPort $DIRPORT"            >> /etc/tor/torrc
echo "ORPort $ORPORT"              >> /etc/tor/torrc
echo "ExitPolicy reject *:*"       >> /etc/tor/torrc
echo "ExitPolicy reject6 *:*"      >> /etc/tor/torrc
 
/etc/init.d/tor restart

tor.txt · Last modified: 2015-09-16 23:22 UTC by rm