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 |
|
Add user to sudo group¶
1 |
|
Log in to user¶
1 |
|
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.
- Create a
authorized_keys
file:
1 2 3 4 |
|
- Insert your public key and save the file with
:wq!
. You can copy this from theauthorized_keys
file under the root account's directory. You can find the file using the following commands:
1 2 3 |
|
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.
- Open
sshd_config
with Vim:
1 |
|
- Add
PasswordAuthentication no
. It might be commented out as#PasswordAuthentication no
or written asPasswordAuthentication yes
. If you find either, replace withPasswordAuthentication no
. Else just add it in.
Vim Tip
Use :/PasswordAuthentication
to find #PasswordAuthentication no
.
-
Save the file with
:wq!
. -
Restart
ssh
to implement this change:
1 |
|
Basic Firewall¶
- List application profiles registered with ufw firewall:
1 |
|
You should see
1 2 |
|
- Ensure the firewall allows SSH connections:
1 2 3 |
|
You should see the following after executing sudo ufw status
:
1 2 3 4 |
|