This guide assumes you are using Ubuntu 18.04 Server, you have screen
installed, and that your server is already uploaded to the server.
This guide also assumes you have a server start script. You can find one here
Screen is a tool used to run processes in the background. It is commonly used to run multiple commands at the same time, but in this case, we'll be using it to run our Minecraft server even if we close our SSH session.
screen -S minecraft
Creates a screen
session with the ID minecraft
. The name is set via the -S
flag. Remember, case-sensitivity is important with command flags.
screen -r minecraft
Enters a screen session that is already running. -r
means 'restore' or 'reattach'. Assuming you're running a Minecraft server in this screen, you'll be sent to the server's console.
Nano is a useful text editor, and can be called with nano
. Personally, I prefer to use nano for quick and easy stuff, such as copying the start script into a bash file.
Assuming we've already entered the server directory with cd
, and the start script is already copied, we can start. Make sure the start.sh
is executable. To make it executable, use chmod +x start.sh
screen -S minecraft
will create a screen session with the default bash command line.
./start.sh
will run the start script. In this scenario, we're using the script I linked in the introduction.
This script will start the Minecraft server. Typing stop
in the console will end the server process, and the script will give us three seconds to exit the loop. Pressing ctrl+c
will stop the script, and thus, exit the loop.
Pressing ctrl+a+d
within a screen session will 'detatch' us from the session. This means that, while we aren't inside the screen session, it is still running and can be reattached to.
screen -r minecraft
will reattach us to the session. In the case of our server, this means we're returning to the server's console.
I often find it's easy to create multiple nested screen sessions. In this case, you can type exit
to kill the screen session.
You can see what screens are attached and dettached by running screen -r
. This will show you all screens, and beside each it will say either (detached) or (attached).
The one that your currently attached to will be suffixed with (attached). Every other screen should say (detached).
By default, created files do not have the ability to be executed. To remedy this, use chmod +x {filename}
.