0

How To: Minecraft Server on Ubuntu

So I’ve been playing Minecraft on the Xbox360 for some time now and it started getting a bit repetitious and bland. My son got into the PC version and I was sitting with him and his friends for a few sessions and it got my interest. This weekend I decided to set up a server so they can have somewhere to put their creations and not have to worry about being kicked from someone else’s server or have their city griefed (Griefing is the act of irritating and angering people in video games through the use of destruction, construction, or social engineering.) as well, they were talking about starting to make YouTube vids so this will be good for them. I thought this would have been harder that what it turned out to be, so for those wanting to do it but are not sure about how go about it or are afraid of getting their hands dirty in Linux, I created this tutorial.

What is Minecraft?

Minecraft is basically and electronic version of Lego but with so much more. The Xbox version is limited but the PC version is just too awesome and huge to put into words in a post as there are so many features and not to mention the mods and customizations that can be made to it. If you are into developing or know how to script you can create your own customizations for Minecraft to make your install yours. As always, if you create something awesome, do share with others. At the end of the article I will post links to related sites.

Minecraft is a sandbox indie game originally created by Swedish programmer Markus “Notch” Persson and later developed and published by Mojang. It was publicly released for the PC on May 17, 2009, as a developmental alpha version and, after gradual updates, was published as a full release version on November 18, 2011. A version for Android was released a month earlier on October 7, and an iOS version was released on November 17, 2011. On May 9, 2012, the game was released on Xbox 360 as an Xbox Live Arcade game, co-developed by 4J Studios. All versions of Minecraft receive periodic updates.
- From Wikipedia, the free encyclopedia

Minecraft is basically a sandbox game where players can break and place blocks to build almost infinite creations. Blocks or Cubes are scaled to 1 cubic Meter and represent different materials like dirt, stone, water, lava, trees and various ores. At start, players spawn with nothing but their two hands and an open world to explore, worlds are divided into biomes ranging from deserts to snowfields. The game has a day-night system as well as a varied weather cycles depending on what biome you are in; like snowfall if you are in a snow biome or rain if you are in another biome.

As the game progresses, players will meet non playable characters knows as mobs. They include non-hostile mobs such as chickens, cows and pigs that can be killed for food. In the nigh-time and in dark areas, hostile mobs are set loose, they include giant spiders, skeletons, zombies and creepers. Skeletons come armed with bow and arrows and creepers are equipped with an explosive charge that go off if they get close to you, they make no noise except for the hiss right before they explode. There are other mobs in the game but we won’t go into them all as each version of the game and the platform you play them on present different features and it is too much for this post. Depending on what version you are playing you may have different mobs as well like wolves (mobs are not hostile unless you hit one, then all hell breaks loose; especially if they are in a pack when you hit one).

Minecraft allows for some sick in-game creations with just the blocks you find in game, even if you have no added mods; for example, with redstone you can create electrical circuits to build primitive mechanics, electrical circuits and logic gates.

There are numerous expansion content that you can add to the game, like mod packs, texture packs, resource packs and custom maps. Mods allows one to add features to the game like elements from Portal and The Hunger Games. The Modding community is HUGE and are mods developed for specific Minecraft Versions.

Ok, now back to the reason you came here in the first place…

How to setup your own server in Ubuntu.

While I set mine up using Ubuntu 12.04, you can choose to use other Linux variants and switch the commands to suite your OS of choice. The reason I used Ubuntu 12.04 is that it is an LTS (Long Term Support) version and will receive support for 5 years which gives me to April of 2017 until I have to upgrade the OS and I prefer to keep with a stable system. For those that don’t know, Ubuntu releases LTS and non LTS versions of their OS; their naming convention rolls with their release schedule, April and October of every year which gives us a 6 month cycle. :) I will be upgrading sooner or later but I prefer to let the kinks be ironed out before I move on, I’m not a bleeding edge person in this respect. Below is a list of their last few releases.

  • Ubuntu 12.04 LTS (Precise Pangolin)
  • Ubuntu 12.10 (Quantal Quetzal)
  • Ubuntu 13.04 (Raring Ringtail)
  • Ubuntu 13.10 (Saucy Salamander)
  • Ubuntu 14.04 LTS (Trusty Tahr)

First things First

I am assuming that you have already installed your Ubuntu OS; if not, go do that before moving ahead. If you are not sure how to do so, I recommend a quick Google search. You WILL want to select the OpenSSH Server option at the Software Selection screen. I am also assuming that you have some basic knowledge of Ubuntu and the Command Line. The tutorial will be broken up into sections and will cover most things that are needed for running Minecraft as well as securing your server.

Required Packages

These packages are needed before we can proceed any further as well as updating your system before we proceed any further. Make sure you have the right apt setup, see here.

Updating and Upgrading

sudo apt-get update && sudo apt-get upgrade
sudo apt-get update && sudo apt-get dist-upgrade

Open-SSH

SSH allows you to connect to your server from another computer for administration, maintenance or troubleshooting. If you did not select this during setup, here is how to install it.

sudo apt-get install openssh-server

UFW – Uncomplicated Fire Wall

UFW is installed by default on most Linux systems, but is not enabled. This means your server is wide open to the entire world. Let’s enable the firewall but first we must add a rule to allow SSH or you will not be able to connect once the firewalls is enabled.

sudo ufw allow 22

Once that rule has been added then we can enable the firewall:

sudo ufw enable

Now we need to enable the other ports we are going to be using. Minecraft runs on a default port of 25565. Run the following command to add the port.

sudo ufw allow 25565

Check the Firewall status to make sure all is setup right:

sudo ufw status

You should see the following:

Status: active
 To                         Action      From
 --                         ------      ----
 22                         ALLOW       Anywhere
 25565                      ALLOW       Anywhere
 22                         ALLOW       Anywhere (v6)
 25565                      ALLOW       Anywhere (v6)

fail2ban

This is a neat little package that keeps track of how many times someone has tried to login to your server (not your MC server, your actual Linux server), and then bans their IP address for a set period of time when someone tries to login via SSH.

Run the command and tell it Yes when it asks if you want to install:

sudo apt-get install fail2ban

The default install on this will probably be fine for you, but you can look at the specific settings in /etc/fail2ban/jail.conf, I use vi to edit.

sudo vi /etc/fail2ban/jail.conf

The Default section contains the default ban length and max retries for all services. You can also set your own IP address to be ignored if you want. The ban time is in seconds, I suggest setting that to a minimum of 24 hours to prevent script kiddies from trying to brute force your machine all day long.

[DEFAULT]
# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = 127.0.0.1/8
bantime  = 86400
maxretry = 3

The SSH section has a different number set for max retry that overrides the default settings. You can change this or leave it as you see fit.

[ssh]
enabled  = true
port     = ssh
filter   = sshd
logpath  = /var/log/auth.log
maxretry = 6

Optimize fail2ban

sudo vi /etc/default/fail2ban

Add the following line:

ulimit -s 256

Restart fail2ban

sudo /etc/init.d/fail2ban stop
sudo /etc/init.d/fail2ban start

htop

This is an awesome tool to keep track of CPU and MEM usage, we use it with Shift+M to list usage by memory highest at the top. To use it simply type htop on the command line.

sudo apt-get install htop

Java

Java is NOT optional, without this Minecraft will NOT run. To install it run the following:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update && sudo apt-get install oracle-java7-installer

Users, Folders and Rights

For security reasons we do NOT want to run Minecraft as root so we will create a minecraft user for this purpose as well as create admin accounts that can edit files and configs for the Minecraft server. Make sure you are using secure passwords, read our article on that here.

sudo adduser minecraft

Create additional users and add them to the minecraft group as needed. The groups command will check the groups a user belongs to.

sudo adduser 
sudo usermod -a -G minecraft 
groups

Where to put the files

You can put the files anywhere you’d like but we prefer to create a root directory to keep everything centralized. We’ll create all the directories first and then assign rights and run modes after.

cd /
sudo mkdir minecraft

Next, create backup directories, we all know how important backups are right?

sudo mkdir minecraft/backups

Assign ownership of the minecraft directory tree to the minecraft user and group as well as set proper run mode.

sudo chown -R minecraft minecraft
sudo chmod -R 775 minecraft

Getting the files and performing first run

Before we do anything else we need to grab the server file and perform a first run to get things setup.

Make sure you are in the /minecraft directoy before proceeding:

cd /minecraft

To get the server file go here and download the server file, the most recent one is minecraft_server.1.7.9.jar. I use wget for my files so run this:

wget https://s3.amazonaws.com/Minecraft.Download/versions/1.7.9/minecraft_server.1.7.9.jar

Rename the downloaded file

sudo mv minecraft_server.1.7.9.jar minecraft_server.jar

Become the minecraft user

su minecraft

Test it out

The following command will start the server, run it with no gui and assign 2GB of ram to the server. Make sure you use an appropriate number depending how much ram your system actually has, this is set in MB so 1GB would be 1024.

#!/bin/bash
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui

During the run you should see a console that will show you the progress of the setup. Once the run is finished you should be able to connect and play.

Once verified, type stop in the console to stop the server so we can proceed.

Editing settings

Enable the whitelist so that nobody can connect while you are working on your server.

  • Set yourself as an op in ops.txt
  • Set your IP address
  • Set any other options you want on your world, such as enabling PvP or Monsters or whatever.

Here is a copy of my server.properties file. The lines in orange are ones that you will need to modify. As per Minecraft, here are the options for op-permission-level:

  1. Ops can bypass spawn protection.
  2. Ops can use /clear, /difficulty, /effect, /gamemode, /gamerule, /give, and /tp, and can edit command blocks.
  3. Ops can use /ban, /deop, /kick, and /op.
  4. Ops can use /stop.
#Minecraft server properties
allow-flight=false
allow-nether=true
announce-player-achievements=true
difficulty=1
enable-command-block=false
enable-query=false
enable-rcon=false
enable-command-block=false
force-gamemode=false
gamemode=0
generate-structures=true
generator-settings=
hardcore=false
level-seed=whatever seed you want
level-name=My World
level-type=DEFAULT
max-build-height=256
max-players=20
motd=Welcome to My World
online-mode=true
op-permission-level=2
player-idle-timeout=0
pvp=true
resource-pack=
server-ip=xxx.xxx.xxx.xxx
server-port=25565
snooper-enabled=true
spawn-animals=true
spawn-monsters=true
spawn-npcs=true
spawn-protection=16
view-distance=8
white-list=false

The ip address will be the address of the server and is for local connection only. For connecting from outside your local network you will need to setup port forwarding and maybe Dynamic DNS settings. These are way too involved to cover here so as usual, Google is your friend.

Enabling whitelisting will create a setup where no one will be able to connect unless they are whitelisted.

I suggest changing the view-distance to 7 to reduce possible lag. This setting handles the way the game loads chunks.

Modded Runs

Here are links to some of the Mod Packs available online.

That’s it for now.. I’ll keep adding to this as I keep playing with my server. Please let me know if I missed anything and share do your tips, I would love to learn some tricks from you.

Ubuntu VPS Hosting via How To: Minecraft Server on Ubuntu.

Minecraft VPS Hosting via How To: Minecraft Server on Ubuntu.