Accessing your server

On Windows, you can use the free Putty SSH client to access your server.

On a Unix-based OS (e.g. Mac OS X), you can use the SSH client in the terminal as such:
ssh <server address> -l <username, should be root for clean setups> -p <port>

Fill in the details on your respective client, and start the SSH session. You might see something about "the authenticity of the server can't be established", that's normal, and just input "y" or "yes". Now, input the password your host gave you (you won't see it in the client, that's convention). You can paste using the right mouse button on Putty, and otherwise, it depends on your terminal.

If your host didn't give you a root account, (OVH sometimes does this), you can skip this and "securing your server".

Once you're inside, you should see the Ubuntu message of the day, and a line on the bottom saying:

root@<machine hostname>:~$

That is the shell you will be using, and let's get this party started.

Securing your server

The root account is the superuser of the system, and as such, you should not run non-administrative tasks using this account.

The first things we will be doing are:

updating your server to the latest packages

setting up a separate user account on your system for running your server

disabling the root account, and enabling escalation via sudo

To update your server, run the following two commands (press enter at each newline):

For example, adduser minecraft. After you've set and verified the password, you don't need to put any more information. Just keep on hitting enter.

Next, we'll be adding the new user to the administrative users list:

usermod -a -G sudo <user name here>

Now, exit your SSH session by running exit, and follow "accessing your server", this time using the account you just created instead of root.

Once you've gotten into your new account, we need to test if it has root privileges. Run a sudo apt-get update, input your password, and see if it runs. If it runs, you're on the right track, otherwise, go back a few steps and check your work.

Now, we need to disable the root account, as we don't need it anymore, and it presents a security risk.
Run sudo passwd -dl root, and now, we'll edit the SSHd configuration so that root can't log in either:

sudo nano /etc/ssh/sshd_config

Find the line that says "PermitRootLogin", and change that to no. Save the file, and then run:

sudo service ssh restart

You should preferably set up public key authentication for proper security, which is outside the scope of this tutorial. See this guide for more information on creating and using public keys.

Now, in case you don't like the spammy Ubuntu message of the day when you log in, you can do:

cd ~
touch .hushlogin

For future reference, ~ is your home directory (a.k.a. folder).

Setting up mark2

mark2 is a server wrapper with advanced monitoring, scripting, and multiuser capabilities that's point-and-click through the SSH session, and is easy to install on Ubuntu. Let's get started.

If you like your freedoms, or the Oracle installer isn't working for some reason, do:

sudo apt-get install openjdk-7-jre-headless

Next, let's get back to your home directory, and make a folder called spigot:

cd ~
mkdir spigot
cd spigot

Upload your spigot-xxx-SNAPSHOT.jar to this directory using your favorite SFTP/SCP client, or run the latest BuildTools on the server (only if your server has more than 1.5GB or so of RAM, otherwise run it locally and upload the JAR, or wget from a precompiled source (be careful)):

You should see mark2 starting the server, and congratulations, you have set up a server with mark2. Connect to your Minecraft server using your VPS' address, and bask in the glory of having set up a Minecraft server.

Accessing your Minecraft console

To access your Minecraft console, run mark2 attach. This is the standard mark2 console, and note that you can click on most things, and control the server that way.

Let's run some sample commands:

version

That gives you the Spigot version you're running. Now, run the following with the tilde to restart the MC server:

~restart

Now, exit mark2 by pressing Ctrl+C. You can reattach using mark2 attach. You can run either~stop in the console or mark2 stop to stop the MC server. This works for multiple logged on users without any additional configuration, unlike screen or tmux.

If you have multiple servers, you can click the server names at the top of the mark2 screen to switch to one of them.

If you're getting special accented characters for mark2, you need to force your SSH client to use UTF-8 encoding.

For Putty, you can go to Window > Translation, and set "received data" to UTF-8. Restart Putty to see the changes.

Scripting mark2, and maintaining uptime

This will be the final "tutorial" component, and will cover:

Automatic restarts

Periodic saves

Starting mark2 automatically if your server restarts

mark2 has a powerful scripting mechanism. I recommend that you review it first before continuing, so that you gain a better understanding of the cron syntax used in mark2 and Linux in general.

Save the file, and stop mark2 by running either mark2 stop or ~stop in the console. Start mark2 by running mark2 start.

If you wish to use Spigot's builtin /restart command, put

#!/bin/sh
mark2 send -n ${PWD##*/} ~restart

in a file named start.sh in your spigot folder. Then, make it executable by running chmod +x start.sh. Now, you can run /restart in-game to restart your server.

Now, in case you need to restart your VPS, let's set it up so that mark2 starts your server automatically:

sudo nano /etc/crontab

Add this to the end, obviously customizing your server location and username:

@reboot <username> mark2 start /home/<username>/spigot

Save the file, and that should be covered. If you really need to test it, you can attempt to restart the server:

sudo reboot

This covers the general server setup using mark2. Sit back, relax, eat a sandwich, and play some Minecraft.

Graphical access

In case you're not feeling like using wget and nano to download plugins and edit configs, or want to easily transfer your existing server, any SCP/SFTP client will do.

WinSCP is a good choice for Windows, CyberDuck works quite well on OS X, and Filezilla is a nice cross-platform solution.

For these clients, just select SCP or SFTP, and use your SSH credentials. Use their respective documentations for usage.

MySQL Server

Some plugins, such as Logblock, require an SQL server. Setting up a server that can be accessed only locally is as easy as:

sudo apt-get install mariadb-server

Input your preferred SQL password (preferably different from your server password), and we can create a database.

First, let's login to the MySQL shell:

mysql -u root -p

Type the password you set earlier, and now, inside the shell:

create database minecraft;
exit

That created a database called minecraft, and exits the shell. SQL queries end with ;.

Now, to use that database in a plugin, fill in the host as localhost, username as root, password as the one you set during the install, and database as minecraft.

If you want to set up multiple SQL users, or access the database remotely, that is outside the scope of this tutorial.
Please use Google for guides.

Tips and tricks

If you're migrating a server, and you can't connect after the migration, check that server-ip in server.properties is either blank or the IP you want it to bind to, and check your Votifier settings (this can cause connection failures).

If you really need a specific version of a JAR, or just want to download files directly, cd into the directory you want to download to, and then:

Some entertainment

<LaxWasHere> You could have just made a bash script. "Minecraft in 2 seconds."
<chiisana> 2 seconds*
<chiisana> *: actual time may vary depending on internet connection speed, and server installation time
<vemacs> Coming soon?!

this is a great tut and i love this system, previously used screen and i was wondering if there was a way to enable colours? it would make it easier for me to distinguish commands form players and the players ranks, ect

@gsand will running the update command above update my mark2(by mcdevs) to your most recent version?
And thank you so dam much for taking up mark2 and for all the work!
And a big big thanks to vemacs for this tutorial too!!