Ubuntu OS Initial Server Setup 12.04 & 14.04/10
Posted by RAJU K, Last modified by RAJU K on 18 January 2016 09:37 PM
Introduction to Ubuntu OS
When you first building a new Ubuntu 12.04 or 14.04/10 server, there are a few configuration steps that you should take early on as part of the basic setup.This will increase the security and usability of your server and will give you a solid foundation for subsequent actions.
Step One — Root Login
To log into your server, you will need to know your server's public IP address and the password for the "root" user's account. Please check your VPS Server Login email for server credentials.
If you are not already connected to your server, go ahead and log in as the
Complete the login process by accepting the warning about host authenticity, if it appears, then providing your root authentication (password or private key). If it is your first time logging into the server, with a password, you will also be prompted to change the root password.
The root user is the administrative user in a Linux environment that has very broad privileges. Because of the heightened privileges of the root account, you are actually discouraged from using it on a regular basis. This is because part of the power inherent with the root account is the ability to make very destructive changes, even by accident.
The next step is to set up an alternative user account with a reduced scope of influence for day-to-day work. We'll teach you how to gain increased privileges during the times when you need them.
Step Two — Create a New User
Once you are logged in as
This example creates a new user called "demo", but you should replace it with a user name that you like:
You will be asked a few questions, starting with the account password.
Enter a strong password and, optionally, fill in any of the additional information if you would like. This is not required and you can just hit "ENTER" in any field you wish to skip.
Step Three — Root Privileges
Now, we have a new user account with regular account privileges. However, we may sometimes need to do administrative tasks.
To avoid having to log out of our normal user and log back in as the root account, we can set up what is known as "super user" or root privileges for our normal account. This will allow our normal user to run commands with administrative privileges by putting the word
To add these privileges to our new user, we need to add the new user to the "sudo" group. By default, on Ubuntu 14.04, users who belong to the "sudo" group are allowed to use the
Now your user can run commands with super user privileges!
Step Four — Add Public Key Authentication (Recommended)
The next step in securing your server is to set up public key authentication for your new user. Setting this up will increase the security of your server by requiring a private SSH key to log in.
Generate a Key Pair
If you do not already have an SSH key pair, which consists of a public and private key, you need to generate one. If you already have a key that you want to use, skip to the Copy the Public Key step.
To generate a new key pair, enter the following command at the terminal of your local machine (ie. your computer):
Assuming your local user is called "localuser", you will see output that looks like the following:
Hit return to accept this file name and path (or enter a new name).
Next, you will be prompted for a passphrase to secure the key with. You may either enter a passphrase or leave the passphrase blank.
Note: If you leave the passphrase blank, you will be able to use the private key for authentication without entering a passphrase. If you enter a passphrase, you will need both the private key and the passphrase to log in. Securing your keys with passphrases is more secure, but both methods have their uses and are more secure than basic password authentication.
This generates a private key,
Copy the Public Key
After generating an SSH key pair, you will want to copy your public key to your new server. We will cover two easy ways to do this.
Option 1: Use ssh-copy-id
If your local machine has the
After providing your password at the prompt, your public key will be added to the remote user's
Option 2: Manually Install the Key
Assuming you generated an SSH key pair using the previous step, use the following command at the terminal of your local machine to print your public key (
This should print your public SSH key, which should look something like the following:
Select the public key, and copy it to your clipboard.
Add Public Key to New Remote User
To enable the use of SSH key to authenticate as the new remote user, you must add the public key to a special file in the user's home directory.
On the server, as the
Now you will be in your new user's home directory.
Create a new directory called
Now insert your public key (which should be in your clipboard) by pasting it into the editor.
Now restrict the permissions of the authorized_keys file with this command:
Type this command once to return to the
Now you may SSH login as your new user, using the private key as authentication.
Step Five — Configure SSH Daemon
Now that we have our new account, we can secure our server a little bit by modifying its SSH daemon configuration (the program that allows us to log in remotely) to disallow remote SSH access to the rootaccount.
Begin by opening the configuration file with your text editor as root:
Next, we need to find the line that looks like this:
Here, we have the option to disable root login through SSH. This is generally a more secure setting since we can now access our server through our normal user account and escalate privileges when necessary.
Modify this line to "no" like this to disable root login:
Disabling remote root login is highly recommended on every server!
When you are finished making your changes, save and close the file using the method we went over earlier (
Step Six -- Reload SSH
Now that we have made our change, we need to restart the SSH service so that it will use our new configuration.
Type this to restart SSH:
Now, before we log out of the server, we should test our new configuration. We do not want to disconnect until we can confirm that new connections can be established successfully.
Open a new terminal window on your local machine. In the new window, we need to begin a new connection to our server. This time, instead of using the root account, we want to use the new account that we created.
For the server that we showed you how to configure above, you would connect using this command. Substitute your own user name and server IP address where appropriate:
Note: If you are using PuTTY to connect to your servers, be sure to update the session's port number to match your server's current configuration.
You will be prompted for the new user's password that you configured. After that, you will be logged in as your new user.
Remember, if you need to run a command with root privileges, type "sudo" before it like this:
If all is well, you can exit your sessions by typing:
Where To Go From Here?
At this point, you have a solid foundation for your server. You can install any of the software you need on your server now. We'll keep posting new tutorials like firewall setup and installation of software stacks soon.
All the best with your cloud server.
Happy VPS Hosting.