«

»

Jun 15

Creating a Server Part 2: Security

The internet can be a hostile place with many people out there intent on hacking other peoples computers and servers. I have found that the basic tips I outline in this blog can help prevent, or at least slow down, hacking of your server. Many of these tips are found on the Ubuntu server guide, I’ve just compiled them here for ease of access, for myself and anyone else.

Passwords

It may seem basic, but many people use the same password for everything, from their email, to bank accounts, and many of these are weak passwords. Try to make sure your passwords are a combination of upper and lower case letters as well as numbers. Within your server it’s a good idea to make sure the “root” or administrator users have different passwords from user you will use on your web server from day to day. This will help prevent full access to your server being comprimised.

Another tip is not to log onto your server as the root user, but as a designated user that has sudo privileges. This is because the root user has full control over the server.

Disabling Ctrl+Alt+Del

It is possible to restart a server from the console by using the Ctrl+Alt+Del key combination. For most servers this functionality is not desired as any user could restart the server, so its best to disable it by editing the appropriate config file

sudo nano /etc/init/control-alt-delete.conf

Once here make sure the following line looks like this:

#exec shutdown -r now "Control-Alt-Delete pressed"

Save the file and the feature is disabled.

Firewall

The purpose of a firewall is to stop ports of the server being accessed when not want. By closing down unused ports it makes it harder for hackers to gain access to the server as there are less “doors” left open to them. Fortunately, Ubuntu comes with a really simple to use firewall call Uncomplicated Firewall (ufw). First of all lets check to see that it is indeed installed

sudo apt-get install ufw

Once installed ufw is really easy to configure. I’m going to assume you have the LAMP set-up I outlined in my previous blog post. First we are going to add the ssh port to ufw before we turn it on, so that we can still access the server, and then we’ll turn it on, then allow Apache access

sudo ufw allow "OpenSSH"
sudo ufw enable
sudo ufw allow "Apache Full"

Thats it the firewall is now up and running, our ssh session hasn’t been disturbed and any websites we had running will still work. Using ufw is easy and by typing in the

ufw --help

you can work out how to use it in no time.

Automatic Updates

Another way to ensure your server is secure is to ensure you have the latest security updates. You can either do this manually or have them automatically applied once they are available. To install automatic update enter the following

sudo apt-get install unattended-upgrades

Next we will set up automatic updates to check for new updates every day, and clear the local archive every week, (this is lifted straight from the Ubuntu server guide).

sudo nano /etc/apt/apt.conf.d/10periodic
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";

And Finally…

I have outlined here only the basic steps to securing your server. There are plenty more ways to lock down your server and make it less vulnerable to attack. For instance, I have not mentioned using certificates to secure your server. Hopefully though, these steps should be a helpful start to preventing attack to your server

Permanent link to this article: http://www.jamestoyer.me.uk/2010/06/15/creating-a-server-part-2-security/