SSD Nodes Learn Hosting plans →
How to do am Matt ConnorBy Matt Connor

How to setup Tor relay for Linux VPS

Learn how to run a guard or middle relay on your Linux VPS. We show you how to configure torrc, manage bandwidth for metered plans, use nyx, and handle the slow consensus ramp.

Wetin Tor relay for VPS dey do

Tor relay na Tor daemon wey dey run for machine wey get public IP address, and e dey forward encrypted traffic for other people. Directory authorities dey publish am, and Tor clients dey build circuits through am. Guard or middle relay dey only pass traffic go another relay, so e no dey open connection to website on behalf of stranger. Na this fact make e no dey attract abuse mail, and na why e fit ordinary VPS well. Relay dey carry other people traffic and e no dey publish anything of its own. So, if wetin you want na to put your own site for the network instead of moving packets for am, running v3 onion service behind nginx na different work wey use the same tor daemon. Running relay no dey protect the privacy of your own browsing too. That one na separate problem, and the limit dey lower than many people expect: wetin self-hosting SearXNG really dey hide fit show how far moving service go your own VPS fit take you.

The work small: one package, fifteen lines of config, one firewall rule, and one restart. The rest of this guide na where things dey go wrong. E cover bandwidth calculation for metered plan, and why a new relay wey dey work well fit look dead for one week.

Guard, middle, bridge or exit: choose one before you install

One daemon dey run all four roles. Your config, together with the directory authorities, dey decide which one you be.

  • Middle relay. E dey receive traffic from a guard and pass am to another relay. E no dey contact destination site. Every new relay dey start here.
  • Guard relay. Na the same configuration, with one flag added. The directory authorities dey give relays the Guard flag after dem don stay fast and stable for long enough. You no dey choose am. You earn am, and na the config below dey help you earn am.
  • Bridge. Na relay wey dem deliberately keep outside the public directory and share privately with users for places wey block Tor. Na the smallest commitment among the four: low bandwidth, no public listing, and the correct first step if your plan small. E also dey run a pluggable transport beside the daemon, most times obfs4, with WebTunnel as another supported option. E use different torrc lines too. how to set up an obfs4 bridge on one cheap VPS dey explain the process, including how to give users the bridge line at the end.
  • Exit relay. Na the last hop, wey dey open the connection to the destination site. Every request wey user make go leave from your IP address, so abuse reports and police inquiries go reach whoever own that address.

Exit no be role wey suppose dey on general-purpose VPS. Run exit only with provider wey don agree beforehand to receive that kind mail, and wey get its own IP address plus published abuse contact. Most standard hosting terms no allow am. If you ignore that, the usual result na suspended server and lost IP address. If na this work you still want do, what running an exit relay actually involves explain how to find exit-friendly host, write the exit policy and reverse DNS, and answer the mail when e arrive. Guard or middle relay dey carry the same user traffic without all that exposure.

Everything below dey build guard/middle relay. ExitRelay 0 na the line wey keep am as one.

Wetin VPS need before you start

The Tor Project publish hard requirements for relays. As of November 2026, dem be: one public IPv4 address for the relay, at least 10 Mbit/s bandwidth for each direction, with 16 Mbit/s recommended, at least 100 GB outbound traffic every month, and 512 MB RAM below 40 Mbit/s or 1 GB above am. No fixed uptime rule dey, but relay wey dey run less than two hours every day no too useful for the network.

The 10 Mbit/s figure describe the line, no be the setting. You need port wey fit handle am. How much of that line you allow the relay to use na separate decision, based on the monthly transfer allowance. Read your plan before you touch the config. If you still dey choose a box, wetin VPS really cost every month explain how dem dey sell transfer allowances, and how to measure the real network throughput of VPS show how to find out wetin the line dey do with iperf3 instead of trusting the sales page.

Harden the machine first. Relay na public service for public address, and people go scan the address within minutes after dem publish am. Lock SSH down to keys and hardened sshd config dey take ten minutes, and e suppose happen before the relay go live, no be after.

Install Tor from the Tor Project repository

Use the Tor Project own apt repository instead of the distribution package. Relay code dey change faster than stable release, so fixes dey reach this repository first, while distribution package dey lag between releases.

sudo apt update
sudo apt install -y apt-transport-https gnupg wget

Add the signing key first, then add the repository. The machine go read the codename by itself, so the same block go work for Ubuntu 24.04 (noble) and Debian 13 (trixie).

wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc \
  | gpg --dearmor \
  | sudo tee /usr/share/keyrings/deb.torproject.org-keyring.gpg >/dev/null

CODENAME=$(. /etc/os-release && echo "$VERSION_CODENAME")
echo "$CODENAME"

sudo tee /etc/apt/sources.list.d/tor.sources >/dev/null <<EOF
Types: deb deb-src
URIs: https://deb.torproject.org/torproject.org/
Suites: $CODENAME
Components: main
Signed-By: /usr/share/keyrings/deb.torproject.org-keyring.gpg
EOF

sudo apt update
sudo apt install -y tor deb.torproject.org-keyring
tor --version

tor --version go print the version wey you just install. If apt update print NO_PUBKEY error instead, apt no get any usable public key to check the release file with. Check say the dearmored key dey for the path wey Signed-By: line name, and say the file fit read: GnuPG dey report key as unavailable the same way when keyring dey exist but permissions no allow am to read. The deb.torproject.org-keyring package important later: e ships the signing key as normal package, so apt go continue to work when dem rotate the key.

Turn on automatic upgrades, then teach dem about the new origin.

sudo apt install -y unattended-upgrades apt-listchanges

For Ubuntu, add the Tor origin to the Allowed-Origins block inside /etc/apt/apt.conf.d/50unattended-upgrades:

Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}-security";
        "TorProject:${distro_codename}";
};

For Debian, the same file dey use Origins-Pattern, where the line to add na "origin=TorProject";. Check the result with sudo unattended-upgrade --debug --dry-run. E go print the origins wey e go act on and e no go write anything.

Torrc wey matter

The package installs one long, heavily commented /etc/tor/torrc. Na only small number of lines matter for relay. Add dem for the end of the file.

Nickname mynicerelay
ContactInfo relay-ops[at]example.com
ORPort 9001
ExitRelay 0
SocksPort 0

Nickname fit get from 1 to 19 characters, and na letters and digits only. E no unique for the network; na the fingerprint be your identity. Na this name you go use find your own relay inside search box, so choose one wey you fit spell for phone.

ContactInfo dey published inside relay descriptor. This one na public document wey anybody fit download, so people go scrape the address. Use address wey you go still dey read after two years, and obfuscate am if you like. This na the only channel wey Tor Project get to warn you about problem with your relay.

ORPort 9001 na the port wey other relays and clients go connect to. 9001 na the conventional choice. Port 443 na another common choice because some restrictive networks allow only outbound 443. So, relay wey dey listen there fit reachable to more clients. Choose 443 only if nothing else for the box need am.

SocksPort 0 dey switch off the local SOCKS proxy, wey relay no dey use, and e remove one listening socket from the machine. ExitRelay 0 dey write this intention for the file: this relay no go ever connect to destination on behalf of user, and anybody wey read the config later no need guess this from the default.

If the VPS get IPv6 address, tor already dey try use am. Since tor 0.4.5, an ORPort line without address dey listen for both IPv4 and IPv6, and e discover the relay IPv6 address the same way e find the IPv4 one. Add second ORPort line with the address inside square brackets only if discovery choose wrong address, and only for address wey you know say reachable. If explicit IPv6 ORPort fail reachability test, relay no go publish its descriptor.

ORPort 9001
ORPort [2001:db8::1]:9001

For 1 GB VPS, add MaxMemInQueues 512 MB. Tor dey decide queue limit from the memory wey e see for the machine. For small shared box, this one fit pass wetin you want am to use. If you set the limit yourself, tor go discard queued cells when pressure high. Relay go survive this, instead of queue growing until kernel kill the process.

Open the ORPort for firewall

Inbound, ORPort must dey reachable from anywhere for internet. Outbound, leave the relay without restriction: e dey open connections to thousands of other relays for plenty different ports, and outbound allowlist go quietly cripple am.

sudo ufw allow 9001/tcp comment 'tor ORPort'
sudo ufw status verbose

Then check the provider own network firewall. Plenty control panels dey run packet filter in front of the virtual machine, and rule wey you add with ufw no get effect there. Because of this, the port fit show as open for the machine but closed from outside. If ufw new to you, the ufw rules wey belong for every VPS go explain the default policy and the order wey rules dey match.

Set bandwidth to match your plan

The manual describes RelayBandwidthRate as a separate token bucket wey limits “the average incoming bandwidth usage for relayed traffic on this node to the specified number of bytes per second, and the average outgoing bandwidth usage to that same value”. Read am twice. The limit dey apply to each direction separately. Relay wey set to 1 Mbit/s fit move 1 Mbit/s in and 1 Mbit/s out at the same time, and provider wey dey meter both directions go bill the total.

ChartMonthly traffic at a sustained relay rate, both directions, 30 days
Di data wey dey behind dis chart
[
  {
    "label": "1 Mbit/s",
    "torrc_rate": "125 KBytes",
    "gb_per_day": 21.6,
    "gb_per_month": "648"
  },
  {
    "label": "2 Mbit/s",
    "torrc_rate": "250 KBytes",
    "gb_per_day": 43.2,
    "gb_per_month": "1,296"
  },
  {
    "label": "5 Mbit/s",
    "torrc_rate": "625 KBytes",
    "gb_per_day": 108,
    "gb_per_month": "3,240"
  },
  {
    "label": "10 Mbit/s",
    "torrc_rate": "1250 KBytes",
    "gb_per_day": 216,
    "gb_per_month": "6,480"
  },
  {
    "label": "20 Mbit/s",
    "torrc_rate": "2500 KBytes",
    "gb_per_day": 432,
    "gb_per_month": "12,960"
  }
]

Those 5 rows na arithmetic, no be measurement: dem show wetin one rate go cost if relay maintain am for full 30 days in both directions. Real relay dey below im cap most of the time, especially for the first weeks. Use the table to remove settings wey no fit work, no be to predict invoice down to the gigabyte. Tor dey count with powers of two, so 125 KBytes na 128,000 bytes per second, about 1.02 Mbit/s: treat the torrc column as the nearest round setting, roughly 2.4% above the rate for the label.

For 1 Mbit/s each way, relay dey move about 21.6 GB per day, so 30 day month go cost roughly 648 GB of metered traffic. This one fit inside 1 TB allowance, with space still left for updates and backups. If you step up to 2 Mbit/s, the month go cost 1,296 GB, and that one don already pass 1 TB plan. The last row, 20 Mbit/s, need 12,960 GB per month and belong on unmetered port. If your provider dey bill outbound traffic only, divide every figure by two. Find out which one you get before you set the rate, because the two answers differ by factor of two.

Now the config. Set rate limit first, quota second.

RelayBandwidthRate 125 KBytes
RelayBandwidthBurst 250 KBytes
AccountingMax 400 GBytes
AccountingRule sum
AccountingStart month 1 00:00

RelayBandwidthBurst na the size of the token bucket, so e allows short spikes above the rate while the average dey hold. About twice the rate na sensible value.

AccountingRule na the line wey plenty operators dey miss. The default na max, wey measures the bigger of the two directions against the quota. The Tor manual also talk say 1 GByte na 102410241024 bytes, no be one billion, so AccountingMax 400 GBytes na about 429.50 GB for decimal units. With the default rule, this one allows about 429.50 GB in and 429.50 GB out, roughly 858.99 GB for meter wey dey count both. AccountingRule sum counts read plus write against the one quota. Na this one transfer allowance actually measures, and e caps the month at about 429.50 GB total.

Write AccountingStart too, never write AccountingMax alone. The quota na the number, while the start line na the period wey e resets on. Quota wey no get period go leave the relay for hibernation, with nothing to bring am back.

Hibernation na blunt instrument. When quota finish, Tor go log this and stop accepting work:

Bandwidth soft limit reached; commencing hibernation. No new connections will be accepted

The relay no go wake exactly when the next period start too. Tor dey track how fast e used the last quota and pick random point inside the new interval, so thousands of relays no go return to the network for the same second. Relay wey dey disappear for the last week of every month go keep losing the stability wey directory authorities dey measure. Set RelayBandwidthRate so the cap no go ever reach, and keep AccountingMax as the backstop wey protects the invoice.

Start and confirm say the relay dey reachable

sudo systemctl restart tor@default
sudo systemctl status tor@default
sudo journalctl -u tor@default -n 50

Within few minutes, the log suppose get this line:

Self-testing indicates your ORPort is reachable from the outside. Excellent. Publishing server descriptor.

This sentence mean say other relays connect back to your ORPort and build circuit through am. Until e show, your relay no dey inside the directory and e no carry any traffic. The error message go look like this:

Your server has not managed to confirm reachability for its ORPort(s) at 203.0.113.10:9001. Relays do not publish descriptors until their ORPort and DirPort are reachable. Please check your firewalls, ports, address, /etc/hosts file, etc.

Check each one in order. ORPort dey open for ufw? E dey open too for the provider separate network firewall? The address for that message na the address wey internet actually route go you, or na private address from NAT setup? Test the port from another machine with nc -vz 203.0.113.10 9001. Tor dey repeat the self test by itself, so once you fix the firewall, e go notice am without your help. Restart go make the test happen immediately.

Your relay permanent identity na the fingerprint:

sudo cat /var/lib/tor/fingerprint

About three hours after dem publish the descriptor, the relay go show for Relay Search. Search the nickname or paste the fingerprint. That page show wetin the network think about your relay: the flags wey e get, the weight wey the authorities give am, and the version wey e dey publish.

Why new Tor relay dey carry almost no traffic?

Because network never measure am yet, and measurement fit take weeks. Tor Project describe the ramp for four phases, and operator wey never read am fit conclude say relay don break and start dey change things. The timeline assume say relay dey reliable, fast, and no be exit relay. Tor Project talk say the descriptions partly come from personal observations, so treat the day counts below as normal examples, no be fixed schedule.

For roughly the first three days, relay no dey measured. E report im own self test result, but until at least three directory authorities vote measured bandwidth for am, consensus go cap im weight at the unmeasured ceiling. Tor Project put this ceiling at 20 KB, so clients almost never choose am. The cap go lift when those measurements arrive, no be when timer finish. From about day three to day eight, bandwidth authorities go measure am properly and the weight go increase. But dem go use am only as middle hop, because no client dey willing to make brand new relay im first hop.

Around day eight, relay go become eligible for Guard flag. Getting the flag go make traffic drop, and this one dey surprise everybody. Clients no dey choose guards as middle hops, because dem assume say guard already busy. So relay go lose middle traffic before e gain guard traffic. E go refill only as clients rotate their guard sets, and this fit take weeks. By roughly day 68, e go reach steady state, where clients wey remove am balance clients wey add am. Steady state mean say the two sides balance, no be say relay dey run at im full configured rate.

So the honest expectation na nothing for three days, something after one week, and settled load after about two months. Change one setting, then wait one week to see wetin e do. Self-hosted Uptime Kuma status page with TCP check against port 9001 na better way to use that nervous energy. E answer the question wey you fit actually control: whether the port still dey answer.

Nyx wey go monitor the relay

nyx na terminal monitor for relay wey dey run. E dey talk to Tor control port, so enable am first for torrc:

ControlPort 9051
CookieAuthentication 1
CookieAuthFileGroupReadable 1

ControlPort dey listen only on 127.0.0.1, and cookie authentication mean say program must read secret file before e fit issue commands. For Debian and Ubuntu, the last two lines don already dey as package default: the tor package own /usr/share/tor/tor-service-defaults-torrc dey set CookieAuthentication 1, CookieAuthFileGroupReadable 1 and CookieAuthFile /run/tor/control.authcookie. So Tor dey write the cookie to /run/tor/control.authcookie as the debian-tor user, and the debian-tor group fit read am from the beginning. Writing the two lines inside torrc only make this setting visible to anybody wey read the config later. Na membership of that group dey allow your own account run nyx without sudo.

sudo apt install -y nyx
sudo adduser "$USER" debian-tor
sudo systemctl restart tor@default

Log out and log back in, then run nyx. The new group must enter your session when you log in, so if you run nyx for the same shell session, e go show permission error for the cookie file even though the config correct. nyx dey show live bandwidth, uptime, the log stream and connection list. For the first weeks, the main thing to watch na the bandwidth graph staying under your RelayBandwidthRate.

More than one relay dey run: MyFamily and family keys

If na only one relay you get, skip this section. If the same operator dey run two or more relays, dem must declare one another. This stop clients from building circuit wey enter and comot through your machines, because that one fit make one operator see both ends.

The long-standing method na MyFamily for every relay torrc, with the fingerprints of all the other relays:

MyFamily AAAAAAAAAA,BBBBBBBB

Every relay dey list every other relay. So, if you add fourth relay, you must edit four files. Tor 0.4.9 add family key wey work together with that list instead of replacing am. Tor manual call the key the future preferred way to advertise a family, but e still say relay families should configure both the key and MyFamily for now. After all your relays don dey run 0.4.9.2-alpha or later, generate one key, then share am:

tor --keygen-family myfamily

This one writes myfamily.secret_family_key and prints one FamilyId line. Copy the key file to every relay, inside the keys subdirectory of the DataDirectory (/var/lib/tor/keys for Debian and Ubuntu), and keep the .secret_family_key suffix. Add the printed FamilyId line to every torrc, then reload with sudo systemctl reload tor@default. Keep the MyFamily list too. Clients wey never understand family keys yet go still read only the old list. Na why the manual dey ask for both.

Wetin dey spoil after e don dey run

The version dey stale. Unattended upgrades go replace the package, but the process wey dey run go continue use the binary wey e start with until something restart am. Compare tor --version for the box with the version wey dey show for the relay's Relay Search page. If dem no match, network still dey see the old one, so restart the service.

The clock dey drift. Consensus documents and certificates all get time limit, so machine wey clock don far out go reject the consensus and stop publishing. timedatectl suppose report say system clock don synchronize. If e no do so, enable systemd-timesyncd or install chrony.

The IP address dey change. Descriptor carry the address, and clients no fit reach address wey don move. After any provider migration or address change, restart tor and monitor for the self-test line again.

The relay slow pass wetin the plan allow. Tor relay crypto efficient for modern processors, and Tor Project estimate say CPU wey support AES-NI fit reach about 400 to 450 Mbit/s for each direction. Long before you reach that limit, port speed and transfer allowance go limit you. Na why the accounting section above matter pass the hardware.

FAQ

How much bandwidth does a Tor relay use?

E go use as much as you allow, and e no go pass that amount. RelayBandwidthRate dey limit relayed traffic for each direction separately, so relay wey you set to 1 Mbit/s fit carry 1 Mbit/s in and 1 Mbit/s out at the same time. This na about 21.6 GB per day, or 648 GB for 30 day month, when you count both directions. Add AccountingMax with AccountingRule sum underneath that rate as hard monthly quota.

Running a Tor relay go bring abuse complaints for me?

Guard or middle relay dey pass traffic only to other Tor relays, and e no dey connect to website for user. So, complaints about wetin person do through Tor go reach exit operator, no be you. Wetin you fit see na scanning and sometimes IP reputation listing, because the address dey publicly listed as relay. Exit relays na the ones wey dey receive abuse mail and legal notices. Dem need provider wey agree in advance to handle am. Read your provider terms before you start either type.

Why my new Tor relay no dey receive traffic?

Na because new relays get throttling by design until dem measure am. Until at least three directory authorities vote measured bandwidth for the relay, consensus go cap its weight. Tor Project set that cap to 20 KB, so clients almost never choose am. For Tor Project typical timeline, bandwidth authorities go measure am from around day three. E go qualify for Guard flag around day eight. Traffic go drop again at that time because clients dey avoid guards when dem dey choose middle hops. Around day 68, e go reach steady state. At that point, clients wey dey drop am go balance clients wey dey add am. This no mean say e dey run at full rate. Confirm say the log show "Self-testing indicates your ORPort is reachable from the outside", then leave am alone.

I fit run Tor relay for VPS with 1 TB transfer allowance?

Yes, at about 1 Mbit/s for each direction, and this na RelayBandwidthRate 125 KBytes. That one na roughly 648 GB every month if your provider dey measure both directions. E go leave extra capacity for updates and backups. Add AccountingMax 400 GBytes with AccountingRule sum and AccountingStart month 1 00:00 so the relay go hibernate instead of passing the plan limit. If the provider dey bill only outbound traffic, you fit double the rate.

I need set MyFamily if I dey run only one relay?

No. Family declarations dey make clients avoid building circuit through two relays wey the same operator own. That one no get meaning when you get only one relay. Set am as soon as you add second relay: list every relay fingerprint inside every relay MyFamily line. Once every relay dey run Tor 0.4.9.2-alpha or later, add the shared family key FamilyId line too. The tor manual currently asks families to configure both, so older clients fit still recognize the family.

Dis article help you?