deploy multiplayer game to linux with the terminal

How to Deploy a Godot Multiplayer Dedicated Server to a VPS

In this tutorial, we will go over how to get a Godot dedicated server up and running on a virtual private server (VPS) running Ubuntu Linux.

This tutorial assumes you already have a VPS with Ubuntu running. There are many companies that allow you to rent VPS’ for very cheap and some even free.

First you need to export your Godot project using the Linux preset. We will only need the .pck file.

It’s also possible to export to other platforms by compiling the server build of Godot. You can find more specific instructions on the official Godot documentation.

SSH into the Server

We then need to SSH into the (VPS) server using the terminal.

If you’re using Windows 10, I highly recommend Windows Terminal. It allows you to create multiple tabs and use the various command line tools that Windows uses such as Command Prompt, PowerShell, and WSL all in one program. It also features more robust visual customization options than the various tools offer on their own.

I will be using Powershell through Windows Terminal in this tutorial, but you can just use regular Powershell too.

First you’ll need the IP address of your server, as well as the login credentials of the user. Your VPS provider should give you this information once you’ve spun one up.

VPS credentials such as IP address username and password

SSH into your VPS. Replace the IP address with the IP address of your VPS. The -l argument defines the username you are logging in as.

ssh 127.0.0.1 -l root

It’s possible you will get an warning that the authenticity of the host can’t be established.

The authenticity of host can’t be established.
ECDSA key fingerprint is SHA256.
Are you sure you want to continue connecting (yes/no)?

If you are renting the VPS from a reputable company, you can safely ignore this warning. Type ‘yes’ to continue.

Next you will be prompted to enter the password.

SSH enter password

As you type, there will be no indication that you have typed anything. This is a standard Linux security feature. It ensures that people watching your screen as you type in your password cannot see how many characters long your password is.

Create a New User

Next we will want to create a new user. The root user has all permissions to edit and change anything and everything in the system. Running third-party software, such as the Godot server build, under these permissions can be a major security risk if the software hasn’t been thoroughly tested. It is safer to create a new user which by default will have more restricted permissions and run programs from that new user’s profile.

adduser diego

You will be prompted to set a password for the new user. This will also create a home directory for them. If it asks for you to enter additional information, you can just leave those fields blank.

Switch User

Let’s navigate to the home directory of the new user. First we need to use cd command to change directory up.

cd ..

You can use the ls command to list the contents of the current directory.

Terminal ls list command

Enter the home directory.

cd home

And then enter the directory of the user you created.

cd diego

We now need to switch our user to the new one we created.

su diego

We alternatively could have switched users first. And then changed directories with cd ~ which brings you to your user’s home directory. But I wanted to show you the cd and ls commands just in case you were unfamiliar.

Transfer the .pck File to the Home Directory

We now need to tranfer the .pck file from our local machine to the VPS. This can be done in the terminal. But you may find a GUI with drag-and-drop features to be more approachable. Just search for an FTP client. I personally use FileZilla since it’s open source.

I will show you how to both transfer the file with the terminal and an FTP client. But you only need to do one of them.

Using the terminal

Open a new terminal tab or window. For this next part we will work from our local machine. Navigate to where you exported the .pck file on your computer using the cd and ls commands.

Once you are there, use the scp command to secure copy the file to the VPS. Be sure to your .pck filename, your VPS’ IP address, and your new user you created. The ~ symbol means we are tranferring to the home directory of the user.

scp .\GameServer.pck diego@127.0.0.1:~

If you go back to the terminal tab/window you used to ssh in, and list the contents of the home directory, you should now see file existing on the server.

Using an FTP Client

FTP client

Most FTP clients have you enter the server’s credentials at the top. Your computer’s files are listed on the left. The server’s files are listed on the right. You can drag and drop the files between the two machines.

Download the Godot Linux Server Build

Go to your web browser and navigate to https://godotengine.org/download/server.

Go to the Linux Server tab. The server build removes all visual elements from your game and includes other optimizations for running on servers.

We need to grab the link location. We will be downloading this file directly from the VPS.

Godot Linux server build

Right-click on the appropiate Server (64-bit) button and copy the link location.

Go back to the terminal tab where you are ssh’d in to the server. We will download the Godot server build directly to the server.

wget https://downloads.tuxfamily.org/godotengine/3.2.3/Godot_v3.2.3-stable_linux_server.64.zip

Once its finished downloading, we need to unzip the .zip file.

Check if your Linux server has the unzip program installed. My Ubuntu server did not, so I will have to install that software.

Unzip not found

If you try to install unzip using the new user, you will get a permission-denied error.

We need to change back to the root user.

su root

And then install unzip.

apt install unzip

Change the user back to your new user. Again, we don’t want to run third-party softare with root permissions.

su diego

Unzip the .zip file.

unzip Godot_v3.2.3-stable_linux_server.64.zip

Run the new Godot server file, specifying our .pck file as an argument. We use the ./ syntax to denote from the current directory run this program.

./Godot_v3.2.3-stable_linux_server.64 --main-pack FPSServer.pck

Start the Godot server

Your Godot dedicated server is now running! Change the IP address you are connecting to in your client. You and your friend’s can now test your game.

3 Comments

  1. Avatar
    Hosein
    March 20, 2021

    Thanks
    It was a very useful tutorial . I’m wondering how I can create and delete multiple game server instances upon users’ requests. For instance, in games like Among us and Pubg there are multiple game servers running , right ? I have no experience in backend development so I don’t know how to achieve this. would u please point me in the right direction to research about it . thank u so much

    Reply
    1. Diego
      Diego
      March 22, 2021

      Hey Hosein,

      That’s a very advanced topic. People make their careers out of that.

      Your implementation would depend on your game’s requirements. The primary issue is scale. How many users will your game have at once?

      You can build a single server that runs a single game instance with a single IP address that players connect to. More servers means renting more VPS’s. Things can get expensive very quickly.

      If your game is simple like Among Us, you can probably get away with using a single VPS to group players together (lobbies) as well as run all the games. You’re really only syncing player’s positions, moment to moment. And a Godot server supports something like 4,000 players.

      A game as popular as Among Us probably needs dedicated matchmaking servers, and separate servers for running the games. And VPS’s are dynamically spun up depending on player count. Of course if your game is popular enough, you could probably afford to hire a network engineer to help out.

      As for further research, a lot developers use AWS to mess around with this sort of thing. It’s relatively cheap and allows you programmatically rent more VPS’s.

      There’s a YouTube channel called Game Development Center where he’s slowly teaching you how to build a MMO in Godot. I’m not exactly sure what server structure he’s going with, but that’s probably the first place I would look.

      Reply
  2. Avatar
    Hosein
    March 24, 2021

    Thank you so much Diego. I appreciate it that u dedicated time to answer.
    Yes it’s indeed an advanced topic as u say.
    I’ll check out that channel to gain more insight.
    Merci

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top