Initial Server Setup with Ubuntu 18.04

Ubuntu Server Created with Sketch.

Updated: 2019-02-17

Root Login

Log into your server, with root user

You will need your server's public IP address. You will also need the password or, if you installed an SSH key for authentication, the private key for the "root" user's account.

What is my public IP?

From your DigitalOcean account, select your project and your public IP will be diplayed. My public IP is

Server IP

The default username is root on most operating systems, like Ubuntu and CentOS.

By default, the password for that user is randomly generated and emailed to you at your account’s email address. A password will not be generated and emailed if you have uploaded SSH keys to your account and chosen Add SSH Keys. Your key will be used automatically and you’ll be prompted for the key’s passphrase if you’ve set one.

Open your terminal and execute this SSH command:

Your logged in! Now what?

Time to tighten some things up!

First, let's create a new user (root is dangerous). We will name our new user term.

That created our user, group and directory. Now we set our user password and some other basic information:

  • Password
  • Full Name
  • Room Number
  • Work Phone
  • Home Phone
  • Other

Set user info

Our user is gonna need sudo!

Right now our user cannot sudo, let's fix that.

Now we can run commands with superuser privileges!

Setup Public Key Authentication

Public Key Authentication is Safer!

Now we are gonna setup Public Key Authentication and turn off password authentication. This will make our server a little more secure and we won't have to enter a password everytime we login.

Generate a Key

First, let's exit out of our server and go back to our local machine.

Now we generate our key.

Hit return to accept the file name and path (or enter a new name).

Next enter a passphrase or leave it blank.

Copy the Public Key up to the Server

We need to copy our Public Key up to our server.

Disable Password Authentication

Log back into your server.

We need to make a couple changes to our /etc/ssh/sshd_config file.

Reload the SSH daemon.

SUDO Without Password

Allow user to sudo without password.

Add this line, with your username.

Setup Our Firewall

Setup UFW firewall

See App List.

Allow SSH connections.

Enable UFW Firewall.

Check status.

Update and Install Package Dependencies

Install PHP 7.2

Add Ondrejs PPA Repo.

Resynchronize package index files.


Install language pack.

Remove PHP 7.0

Add PHP 7.2 CLI

Add Other Packages

Remove unused packages

Restart server

Install the Nginx Web Server

Nginx Web Server

Install Nginx Web Server.

Allow HTTP connections.

Check status.

Check which IP address is accessible.

Install MySQL

Installing and Configuring MySQL Database

Installing MySQL Database.

Run MySQL script to secure the installation.

Set a password for root MySQL user.

Check authentication method of each MySQL user accounts.

Configure the root account to authenticate with a password.

Flush the privileges.

Exit MySQL.

Add Ubuntu's universe repository.

Install the php-fpm module along with an additional helper packages.

Create MySQL User and Database

Create our database.

Create our database user.

Give your user privileges.

Flush the privileges.