Skip to content

Ubuntu 18.04

Last updated on: 10 March, 2019
Compiled by: Evan Tay

In this section you will find my notes on setting up and securing Ubuntu 18.04. Vim knowledge is assumed.

Creating a new non-root Sudo user

It is recommended to avoid using the root user account on a regular basis as it compromises security and is risky. Instead, create a new user account and add it to the sudo group.

Add a new user

1
adduser evan

Add user to sudo group

1
usermod -aG sudo evan

Log in to user

1
su evan

Only allow Key Authentication

Password-based authentication is susceptible to brute-force attacks. Thus, it is good practice to disable it and only allow key-based authentication.

Add Public Key to User

As mentioned, usage of the root user account should be avoided. Hence, it is advisable that you add your public key to the user account you created earlier on. It is assumed that you logged into your root account using SSH key.

  1. Create a authorized_keys file:
1
2
3
4
su evan
cd ~
mkdir .ssh
vim .ssh/authorized_keys
  1. Insert your public key and save the file with :wq!. You can copy this from the authorized_keys file under the root account's directory. You can find the file using the following commands:
1
2
3
su root
cd ~
vim .ssh/authorized_keys

Vim Tip

Toggle visual mode by pressing v at the start of the line for the public key you wish to copy over. Press $ to move the cursor to the end of the line; doing so highlights the entire line. Press y to yank (copy). Then exit the file using :q!.

Enter the destination authorized_keys file. Press p to paste what you yanked.

Disable Password Authentication

As it is assumed that you logged into your root account using SSH key, this step could be unnecessary. However, do still perform a check to verify that PasswordAuthentication no is in place.

  1. Open sshd_config with Vim:
1
sudo vim /etc/ssh/sshd_config
  1. Add PasswordAuthentication no. It might be commented out as #PasswordAuthentication no or written as PasswordAuthentication yes. If you find either, replace with PasswordAuthentication no. Else just add it in.

Vim Tip

Use :/PasswordAuthentication to find #PasswordAuthentication no.

  1. Save the file with :wq!.

  2. Restart ssh to implement this change:

1
sudo systemctl restart ssh

Basic Firewall

  1. List application profiles registered with ufw firewall:
1
sudo ufw app list

You should see

1
2
Available applications:
  OpenSSH
  1. Ensure the firewall allows SSH connections:
1
2
3
sudo ufw allow OpenSSH
sudo ufw enable # Enable firewall
sudo ufw status # Check if OpenSSH is allowed

You should see the following after executing sudo ufw status:

1
2
3
4
To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)

Resources

  1. Initial Server Setup with Ubuntu 18.04
  2. How to Set Up SSH Keys on Ubuntu 18.04

Comments