Use case · Game server

Terraria dedicated server on Linux: install, serverconfig.txt, port 7777

A Terraria dedicated server is the TerrariaServer binary from the official server zip, started on Linux with a serverconfig.txt that names the world, the player cap and the port, and listening on TCP 7777 by default. This page covers the vanilla install as the official Terraria wiki documents it, the config keys that matter, saving and backups, and TShock for when you need accounts, groups and plugins.

See the game server machines

Resource figures from the documentation

The vanilla server's published requirement is memory, not cores: the wiki's Server page asks for about 500 MB of free RAM for a small world and notes that the figure grows with world size and the number of connected players. No CPU figure is published. TShock's install guide sets its own floor at 1 GB of memory.

ItemDocumented valueSource
Free RAM, vanilla, small worldabout 500 MB, more for larger worlds and more playersTerraria wiki, Server
Memory, TShockat least 1 GBTShock wiki, Home
Listening portTCP 7777 (default)Terraria wiki, Server
Player cap16 by default, 1 to 255 via maxplayersTerraria wiki, Server
World size at autocreate1 small, 2 medium, 3 largeTerraria wiki, Server

Two behaviours affect planning. The server hibernates when nobody is online, and world time only advances while players are connected, so an idle world costs almost nothing. It autosaves periodically, but on shutdown it saves only through the exit command; since 1.4.5.0 it also saves when the last player leaves.

Where a whole machine fits

One small vanilla world will not load a modern server. A dedicated machine earns its place when it carries several worlds on separate ports, a TShock instance with plugins beside a vanilla one, other game servers, or a panel such as Pterodactyl that runs them all. On our game server machines you get the whole box: every core, all the memory, root and no neighbours.

  • Every server ships with an unmetered port and one IPv4; nothing counts the traffic.
  • Five cities on our own network, AS19624: New York, Miami, San Francisco, Amsterdam and Bucharest. Pick the one nearest your players; the Looking Glass runs ping and traceroute from our New York and Bucharest routers if you want to measure first. The locations page describes each city.
  • Rack servers and blades carry an out-of-band controller (iLO, iDRAC or BMC) with a browser console once you add a console login, so a broken firewall rule is recoverable without a ticket.
  • A racked machine is live about 30 minutes after the order is approved; a build to order takes 4-24 hours.
  • Ubuntu installs in one click on the Linux lines, which is what the steps below assume.

Installing the vanilla server

The steps below follow the wiki's Linux section. Running the server as its own unprivileged user is our addition, not the wiki's; it keeps a game process away from root. The zip name carries the version: 1458 is server 1.4.5.8, the current one when this page was written. Check the wiki's download list for a newer zip before you copy the URL.

sudo apt update && sudo apt install -y wget tmux unzip
sudo useradd -m -s /bin/bash terraria
sudo -iu terraria

wget https://terraria.org/api/download/pc-dedicated-server/terraria-server-1458.zip
unzip terraria-server-1458.zip
cd 1458/Linux
chmod +x TerrariaServer.bin.x86*

# keep the console in a named tmux session
tmux new -s terraria
./TerrariaServer.bin.x86_64 -config ~/serverconfig.txt
# detach: Ctrl+b then d
# reattach later: sign in over SSH, sudo -iu terraria, tmux attach -t terraria
  1. Write ~/serverconfig.txt (next section) before the first start; the server reads a config file only when it is passed with -config.
  2. World files live in ~/.local/share/Terraria/Worlds/. Copy an existing .wld there to host a world made on a PC.
  3. If the console fails to draw, the wiki's fix is export TERM=xterm before starting.

serverconfig.txt keys that matter

The config is one key=value per line; lines starting with # are comments. With world pointing at a file that does not exist yet and autocreate set, the server generates the world on first start and loads it afterwards.

# /home/terraria/serverconfig.txt  (chmod 600: it holds the password)
world=/home/terraria/.local/share/Terraria/Worlds/main.wld
autocreate=2
worldname=main
difficulty=0
maxplayers=8
port=7777
password=pick-a-long-one
motd=Welcome. Be nice to the Guide.
secure=1
upnp=0
npcstream=60
banlist=banlist.txt
KeyEffect
autocreatecreates the world if missing: 1 small, 2 medium, 3 large
difficulty0 Normal, 1 Expert, 2 Master, 3 Journey
maxplayers1 to 255; the default is 16
secure1 turns on the extra cheat protection
upnpautomatic port forwarding; pointless on a server with a public address, so 0
npcstreamlower means less enemy skipping and more bandwidth; 0 is off
priorityprocess priority: 0 Realtime, 1 High, 2 AboveNormal, 3 Normal, 4 BelowNormal, 5 Idle; on a box of its own you can leave it out
journeypermission_*Journey powers: 0 locked, 1 host only, 2 everyone

Console commands, saving and backups

Commands are typed into the server console without a slash. The ones you will use: help, playing (who is online), save, exit (save and stop), exit-nosave, kick NAME, ban NAME, password NEWPASS, motd TEXT, say TEXT, settle (settle liquids) and dawn, noon, dusk, midnight to set the time. Unbanning is manual: delete the player's name and IP from banlist.txt.

Because the console lives in tmux, cron can send it save and copy the world folder a minute later. The schedule and retention below are ours; adjust both. Note the escaped % signs, which cron otherwise treats as newlines.

# as the game account: sudo -iu terraria, mkdir ~/backups, crontab -e
*/30 * * * * tmux send-keys -t terraria 'save' Enter && sleep 60 && tar czf ~/backups/worlds-$(date +\%F-\%H\%M).tar.gz -C ~/.local/share/Terraria Worlds
15 4 * * * find ~/backups -name 'worlds-*.tar.gz' -mtime +7 -delete

Stop the server with exit, never by killing the process or the tmux session: a hard stop loses everything since the last autosave.

Firewall and access

The wiki states that the server runs on TCP 7777, and its section on cloud machines says to open 7777 for both TCP and UDP. With ufw, allow OpenSSH before anything else so the running SSH session survives ufw enable, then add one rule for 7777/tcp and one for 7777/udp. A second world on the same box needs its own port value and its own rule.

Set password unless the server is meant to be public, and keep secure=1. The password sits in plain text in the config and is also visible in ps output if you pass it with -pass on the command line, which is why the config file route and chmod 600 are better.

TShock: accounts, groups, plugins

The wiki lists TShock as a third-party server package. It adds user accounts, permission groups, in-game admin commands, automatic backups and a plugin interface. It ships its own launcher, TShock.Server, and needs the .NET runtime its install guide names, plus at least 1 GB of memory.

  1. Install the .NET runtime version the TShock install guide asks for, download the latest Linux release from the project's GitHub releases and unzip it into one folder.
  2. Run ./TShock.Server. It creates a tshock folder holding config.json, sscconfig.json and tshock.sqlite.
  3. Join, read the one-time setup code from the server console and type /setup CODE in chat. If the port is already reachable, stop TShock with exit, set ServerPassword in tshock/config.json and start it again first.
  4. Create the owner account with /user add NAME PASSWORD owner, log in with /login, then type /setup again to switch the setup system off.

Defaults worth checking in config.json: ServerPort 7777, MaxSlots 8, BackupInterval 10 minutes with copies kept for BackupKeepFor 240 minutes in tshock/backups, and RestApiEnabled false with RestApiPort 7878. Leave the REST API off, or firewall 7878 to your own address if you turn it on. Back up tshock.sqlite: losing it means setting TShock up again.

When this is the wrong place for it

  • A few friends who all play at the same time can use the game's own host-and-play; a server that runs while nobody is on buys you little, since the server hibernates anyway.
  • The download is the PC dedicated server. The wiki's Server page says nothing about crossplay with console or mobile players, so this page does not either.
  • We run the hardware, the network and the console. Terraria, TShock and their updates are yours to run.

Questions

Which port does a Terraria server need open?

TCP 7777 unless you change port in serverconfig.txt. The wiki's advice for cloud machines is to open 7777 for TCP and UDP. Each additional world on the same machine needs a different port and its own firewall rule.

How much memory does a Terraria server use?

The wiki puts it at about 500 MB of free RAM for a small world and says it rises with world size and player count. TShock's guide asks for at least 1 GB. Neither source publishes a CPU requirement.

Does the server save the world by itself?

It autosaves now and then, saves when the last player leaves on 1.4.5.0 and later, and saves on shutdown only through exit. Run save before copying the world files, or use exit and copy them afterwards.

How do I keep the server running after I log out of SSH?

Start it inside tmux, as the wiki suggests, and detach with Ctrl+b then d. A named session such as tmux new -s terraria also lets cron send console commands with tmux send-keys.

Can I upload a world I already played on my PC?

Yes. Copy the .wld file into ~/.local/share/Terraria/Worlds/ on the server and point world in serverconfig.txt at it. Stop the server with exit before replacing a world file it has loaded.

Should I run vanilla or TShock?

Vanilla is enough for a private world behind a password. TShock is worth it when strangers join: per-player accounts, permission groups, in-game bans and scheduled backups. It costs more memory and its own update cycle.

Put your worlds on a whole machine

Root, an unmetered port and a city near your players, and an out-of-band console on rack servers and blades.

See the game server machines

Related on Server Room

Other use cases