How to Run a Secure Tor Server

Encrypt Storage and Swap Space

Make sure that any sensitive files are stored on an encrypted filesystem and
that file permissions are set correctly. With a Tor server, the only
sensitive information is the server's private key (located in
/usr/local/etc/tor/keys on Unix/Linux platforms; readable only by owner).

Additionally, swap space on the machine should be encrypted if your
operating system has such an option. On some operating systems, it is
possible to have swap space be a file on an encrypted filesystem.

Linux

For 2.4 kernels you either need the ​loop-AES or the ​Cryptoloop patch. A forward port of the Cryptoloop patch is available ​here.

When compiling the kernel for cryptoloop include CONFIG_BLK_DEV_CRYPTOLOOP=y and the ciphers you want to support. For loop-aes only CONFIG_BLK_DEV_LOOP=y is necessary once the kernel has been patched.

Loop-AES on systems with VIA Padlock can use the hardware AES acceleration by building with the following arguments:

make PADLOCK=y KEYSCRUB=y

Sample script to encrypt swap and /tmp.
It encrypts /dev/hda2 (swap) and /dev/hda5 (/tmp) with AES.
If you want a more complex setup (random ciphers etc) check out ​EncSwap.

On Debian, running at least a 2.6.4 kernel, encrypting swap is simple as doing
a aptitude/apt-get install cryptsetup.
After you compiled support for ​DM-CRYPT (Under Device Drivers---> Multi-Device Support (RAID and LVM)---> CONFIG_BLK_DEV_DM=y CONFIG_DM_CRYPT=y) and
the ciphers you want to support add the following to /etc/crypttab

In addition to encrypted filesystems, keeping temporary files in a memory file system
is an option. This means you're using system memory as a hard drive and when the partition
is unmounted the files stored are lost.

Adding the following to /etc/fstab, where /dev/wd0b is your swap, creates two
74M MFS partitions for /tmp and /var/tmp:

When this policy is enabled, it causes the system pagefile to be cleared upon clean shutdown. If you enable this security option, the hibernation file (hiberfil.sys) is also zeroed out when hibernation is disabled on a portable computer system.

For Windows 2000/2003/XP and the 64bit versions of these (running FAT/FAT32/NFTS): The open source project ​TrueCrypt with its extensions ​TCGINA and ​TCTEMP allows transparent encryption with e.g. AES, Twofish, Blowfish of Windows' temporary files directory, user profiles and general data containers. Therefore with True'Crypt/TCGINA/TCTEMP you will be able to ensure that any sensitive files (including the server's private key and swap space) are stored inside encrypted containers as recommended above. A step by step explanation how to install and set this up can can be found ​http://sjspublications.supersized.org/archives/1-Use-Truecrypt-to-Make-Your-Windows-TORServer-Safer.html.

​BestCrypt is similar to True'Crypt but does not offer as many features. Best'Crypt also creates and supports encrypted virtual disks, which are visible as regular disks with corresponding drive letters.

To use EFS built into Windows XP Professional, browse to Documents and settings\<username>\Application Data and right click on the Tor
directory and select Properties. In the general tab click on the Advanced tab and tick the "Encrypt contents to secure data"
See the Microsoft resource document above for me details.

TODO: Give instructions on setting up encrypted filesystems and swap on
various OSs (hopefully including OS X).

*Finder -> Applications -> Utilities -> Disk Utility
*Click "New Image"
*Choose an appropriate location, name and size for the Image
*Change the default encryption field from "none" to "AES-128"
*Click on the "Create" button
*Close Disk Utility after the image has been created

Drag-and-drop the files you want encryped into the newly created image

Follow all Security Updates for Your Operating System

This is probably one of easiest, and most important, things you can do.

Also, if your operating system has support for signed updates, you should
make sure that you enable it.

Physical Security

Make sure that the machine running your Tor server is physically secure. If
it is in a cabinet or rack in a colocation facility, make sure the door(s)
is/are locked. If it is in a machine room in your office, make sure the door
to the machine room is locked.

Keep in mind that DDR memory chips can retain it's contents for one or two minutes if they are freezed immediately after powering off.
The best solution is to wipe whole memory contents during shutdown to avoid revealing passwords that are stored in plain text in memory.
You can also prevent the attacker to boot quickly your machine by locking usb ports and removing cd drive from machine.

Eliminate All Unnecessary Services and User Accounts

Ensure that your Tor server is not running any unnecessary services. Many
(well, most) operating systems come out of the box with extraneous services
running by default. Turn them off. Ideally, your Tor server would run on a
dedicated machine with no user accounts and no services other than Tor
itself.

If you must run other services, lock them down to the extent possible. For
example, you can set OpenSSH to only allow certain user accounts to connect with the AllowUsers option,
or you can firewall your system such that only certain IP addresses are
allowed to connect to the SSH service on your server. The same applies for
most HTTP servers.

Reliability

Make sure your Tor server has good, battery-backed power and reliable
network connectivity. Make sure to use stable operating system software and
good quality hardware, so that the system does not suffer from undue crashes
or other failures.

Minimize Data Retention

Audit your server's logging configuration and reduce the amount of
information logged as much as possible. Set your log rotation software to
delete logs after as short a time as you can manage.

Remember, you can recover deleted files as long as the space has not been
overwritten. With mildly expensive computer forensics, you can recover even
multiple pass overwrites.

The best policy is to keep no logs. If you must keep logs, consider rotating
them and purging the old logs with an overwrite scheme such as Peter Gutmann's
35 pass overwrite using special patterns.

Install Tor and Other Software Carefully

Tor, and many other software packages, are released along with digital
signatures. These signatures allow you to verify the integrity and
authorship of the software. Download the signatures and verify them!

If possible, read and audit the source code to applications you install,
including Tor.

Operating System Paranoia

Some operating systems come in "high security" flavors, such as ​Security Enhanced Linux,
​TrustedBSD and ​OpenBSD. These systems offer advanced
security mechanisms such as mandatory access control (MAC), application
sandboxing, resource management knobs, and so on. Consider using them if
they exist on your system and would help.

Chroot is a good jail for root privilege processes only on FreeBSD 4.x or newer. On other platforms, chroot is a ​corruptible jail ! For those not reading this link, you need to know that the corruption works with a hole in tor, and a hole in the platform to get root privileges. If you do not run Tor as root, nor provide any suid executables within the chroot environment you are not at risk.

Run Tor with Systrace in OpenBSD

You can use this with or without chrooting tor. You can use this with other operating systems that systrace supports such as GNU/Linux. You will
probably have to change some of the file locations.

Running 'systrace -A tor' will generate a default policy for you (note: this provides no protection at this point). After you
have a generated policy, you can use this one below to refine it. After you have it configured for your system,
then when you run systrace with -a it will enforce the policy which provides protection.

"Windows XP and Windows Server 2003 and later support functionality called Software Restriction Policy, also known as SAFER, which allows a user or software developer to run code at a lower privilege without having the user enter credential information when the application starts. For example, an administrator could run an application as a normal user by stripping out certain SIDs and privileges from the application's token as the application is launched. Some applications, most notably Internet-facing applications, such as a Web browser, instant messaging, or e-mail client, should never be run under an administrative context."