How to host a Rust server in Linux
Ever wondered how to make your own server but couldn’t due to the OS restriction to Windows? Well fear no more! This section of the guide will focus on the realm of Linux but more particularly on the Debian 8 x64 distribution. Rather than solely being focused on vanilla Rust I will also branch into Oxide and security of your server itself.
This bit will be the longest part of the guide but will serve you well in terms of the security of your server. This will be mainly focused on people who aren’t familiar in terms of security or Debian in general.
- Login to your server through SSH (PuTTY is recommended).
- Head over to a PasswordGenerator site and generate a random password with a length of 50+ and copy it. Then type “passwd root” and then right click twice in the terminal.
- Now your root password is secure you need to update the software by doing “apt-get update -y && apt-get upgrade -y” then “apt-get install fail2ban nano -y”.
- Now download PuTTYgen then generate the key. Now type all of these individually on a per line basis in PuTTY:
chmod 0700 ~/.ssh
chmod 0644 ~/.ssh/authorized_keys
Now head back to PuTTYgen then right click inside the box with lots of characters and press select all then copy. Now head back to PuTTY where you left off at the nano editor and right click to paste your public key in then do ctrl+o -> enter -> ctrl+x.
Now type “nano /etc/ssh/sshd_config” then ctrl+w then “PasswordAuth” then enter. Now remove the hash and change the yes at the end to a no. Now page down to the bottom and change UsePAM to no. Now ctrl+w and do type PermitRootLogin and simply change it to “without-password”. Now press ctrl+p (save) and ctrl+x (exit) and then finally type “service ssh reload”
Now you just need to open PuTTYgen back open and save the public and private key in a folder somewhere safe. Now close PuTTY and reopen it then simply on the left side goto Connection -> SSH -> Authentication then browse and select your private key file that you just saved. Once you’ve done that head back to Session then click Default Settings then Save then open for a passwordless login.
Valve have their own documentation for setting up SteamCMD you can find this here. Once your at app_update section you type “app_update 258550”.
Once you’ve done the above with SteamCMD it is now smooth sailing you now do “cd directorysetwithsteamcmd” and then nano startrust.sh and paste this:
clear while : do
exec ./RustDedicated -batchmode -nographics \
-server.ip IPAddressHere \
-server.port 28015 \
-rcon.ip IPAddressHere \
-rcon.port 28016 \
-rcon.password "rcon password here" \
-server.maxplayers 75 \
-server.hostname "Server Name" \
-server.identity "my_server_identity" \
-server.level "Procedural Map" \
-server.seed 12345 \
-server.worldsize 3000 \
-server.saveinterval 300 \-server.globalchat true \
-server.description "Description Here" \
-server.headerimage "512x256px JPG/PNG headerimage link here" \
-server.url "Website Here"
echo "\nRestarting server...\n" done
You will need to fill in your own values such as world seed (Map Preview Generator) etc. Now do “chmod u+x startrust.sh” then “./startrust.sh” which will start your server. If there is no hitches within just a few minutes you will be able to connect through RCON. Then ingame through the server list or “connect ipaddresshere:28015”. Once ingame you can refer to our Console System Guide to setup your admin status.
This modded version of Rust is very popular so here is how to set it up. First things first you need to do “wget https://github.com/OxideMod/Snapshots/raw/master/Oxide-Rust_Linux.zip”. Then if you haven’t already install unzip “apt-get install unzip -y” then “unzip Oxide-Rust_Linux.zip” while your in the main rust directory set by SteamCMD then accept any override prompts. Then you do “chmod u+x CSharpCompiler” to ensure cs plugins being able to work such as the Kits plugin. Now you have a fully working Oxide Server. You can refer to here for aspects such as Permissions and making yourself aware of current Rust and Oxide issues.
This is just as easy. You simply need to redo the SteamCMD steps and if you’ve using Oxide you redownload it after updating rust through SteamCMD using link above then unzip it and potentially chmod the CSharpCompiler again.
Firewall (advanced users)
For extra security, you can change the firewall settings. Warning: This is for advanced users and could block access to other services on your box (like teamspeak).
Type “nano iptables.sh” then copy/paste this:
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 28016 -j ACCEPT
iptables -A INPUT -p udp --dport 28015 -j ACCEPT
iptables -I INPUT 1 -i lo -j ACCEPT
iptables -P INPUT ACCEPT
iptables -A INPUT -j DROP
apt-get install iptables-persistent -y
invoke-rc.d iptables-persistent save
Then type “chmod u+ux iptables.sh” then type “./iptables.sh”. This will then execute a bunch of commands which will ultimately just allow the standard ssh port (22) and then the two standard rust ports for later.