Initial Server Setup with Ubuntu
Initial Server Setup with Ubuntu
- When you first create a new ubuntu 18.04 server, there are a new 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.
- This guide below demonstrates how to manually complete the steps recommended for new ubuntu 18.04 servers. Following this procedure manually can be useful to learn some basic system administration skills and as an exercise to fully understand the actions being taking on my server. As an alternative, if you wish to get up and running more quickly, you can run my initial server setup script which automates these steps.
step 1 logging in as root
- If you are not already connected to your server, go ahead and log in as root user using the following command, substitute server’s ip with your server’s public ip address.
1
ssh root's ip
- Accept the warning about host authenticity if it appears. If you are using password authentication, provide your root password to login in. If you are using an SSH key that is passphrase protected, you may be prompted to enter the passphrase the first time you use the key each session. If this is your first time logging into the server with a password, you may also be prompted to change the root password.
- about root
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 discouraged form 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. I will teach you how to gain increased privileges during the times when you need them.
step2 creating a new user
- Once you are logged in as root, we are prepared to add the new user account that we will use to log in from now on.
- This example create a new user named wenyao
1
adduser wenyao
- 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 to skip.
step3 granting administrative 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 superuser or root privileges for our normal account. This allow our normal user to run commands with administrative privileges by putting the word “sudo” before each command.
- To add these privileges to our new user, we need add the new user to the “sudo” group. By default, on ubuntu 18.04, users who belong to the “sudo” group are allow to use the “sudo” command.
- As root, run this command to add new user to the sudo group.
1
usermod -aG sudo wenyao
- Now, when logged in as your regular user, you can type “sudo” before commands to perform actions with superuser privileges.
step4 setting up a basic firewall
ubuntu 18.04 servers can use the UFW firewall to make sure only connections to certain services are allowed. We can set up a basic firewall very easily using this application.
Different applications can register their profiles with UFW upon installation. These profiles allow UFW to manager these applications by name. OpenSSH, the service allowing us to connect to our server now, has a profile registered with UFW. You can see this by typing:
1
ufw app list
the output will looks like this:
1
2Available applications:
OpenSSHWe need make sure that the firewall allows SSH connections so that we can log back in next time. We can allow these connections by typing:
1
ufw allow OpenSSH
Afterwards, we can enable the firewall by typing:
1
ufw enable
You can see that SSH connections are allowed by typing:
1
ufw status
the output will looks like this:
1
2
3
4
5
6
7Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)As the firewall is currently blocking all connections except for SSH. If you install and configure additional services, you will need to adjust the firewall setting to allow acceptable traffic in.