Reader small image

You're reading from  Webmin Administrator's Cookbook

Product typeBook
Published inMar 2014
Reading LevelIntermediate
Publisher
ISBN-139781849515849
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Michal Karzynski
Michal Karzynski
author image
Michal Karzynski

Michał Karzyński, with a scientific research background in the areas of molecular biology and bioinformatics, has been running Unix-like operating systems since 2002. He works as a web application developer, programming in dynamic languages such as JavaScript, Python, Perl, and PHP. He specializes in designing programming interfaces between servers and client applications based on the HTTP protocol. He has been using Webmin for over five years to assist in setting up and managing servers. He is currently employed as a project manager at the Gdańsk University of Technology in Poland. His blog can be found at http://michal.karzynski.pl.
Read more about Michal Karzynski

Right arrow

Chapter 3. Securing Your System

In this chapter, we will cover the following topics:

  • Setting up a Linux firewall

  • Allowing access to a service through the firewall

  • Verifying your firewall by port scanning

  • Turning off unnecessary services

  • Verifying the strength of passwords

  • Disabling root login over SSH

  • Restricting Webmin access to a specific IP

  • Connecting to Webmin securely over an SSH tunnel

  • Closing inactive Webmin sessions automatically

Introduction


Some people say that the only secure machine is one that is switched off. This may be true, but that machine is not very useful. If you want to make your server more functional, you'll have to turn it on and most likely expose it to the curious eyes of the Internet.

Online computer security is a topic large enough to deserve its own book. In fact, a whole shelf of such books is readily available. In this chapter, we will learn basic techniques, which will allow you to secure your server before putting it up online. If your server is exposed to the Internet, it will be a good idea to follow up by doing more in-depth security research and monitor what's happening to your machine on a day-to-day basis. Because this is a book on Webmin, we will only address topics in which Webmin can assist you.

This chapter is divided into three parts:

  • We'll begin by running through a basic checklist of security issues that every system administrator should keep in mind. We'll point to the recipes...

Setting up a Linux firewall


Linux systems have a firewall software built right into the kernel. This packet-filtering framework is called netfilter (since Linux 2.4). It is controlled by a tool called iptables, which instructs the kernel what to do with incoming and outgoing network packets.

In this recipe, we will begin with an empty iptables configuration (firewall disabled) and configure it to drop any incoming packets except those we specifically allow. Before we set up a firewall, we should review some basic concepts related to network communication and the organization of iptables.

The following are some basic packet-filtering concepts:

  • Packets: The Internet is a packet-switched network. This means that all communication is facilitated by breaking up the content into small blocks called packets, which are routed from one computer on the network to another.

  • IP address: The adresses of machines on the Internet are specified by numerical IP addresses, such as 93.184.216.119 (IPv4) or 2606...

Allowing access to a service through the firewall


Once your firewall is set up, all unauthorized traffic coming into your server will be dropped. If you decide to add a service to your server, you'll need to add another firewall rule to allow the incoming traffic to reach the service. Otherwise, external users will not be able to access the new service. In fact, they will not even be able to see that the service is running and their connections will simply time out.

Getting ready

Make sure that your firewall is set up. Refer to the Setting up a Linux firewall recipe for more information. Make sure you know which port numbers and protocols are used by the service to which you want to allow access. Common port numbers such as 80 and 443 for a web server and 20 and 21 for FTP are listed in the file /etc/services. Usermin uses the port 20000 by default.

How to do it...

Perform the following steps for accessing a service through firewall:

  1. Navigate to Networking | Linux Firewall.

  2. Click the Add rule...

Verifying your firewall by port scanning


After your firewall is configured, you may wish to check that you haven't unintentionally left any unnecessary open doors. A good way to do this is to initiate a scan from another machine that will tell you what open ports it discovered on your server. Only ports associated with services that you want to make publicly accessible should be found.

Getting ready

We will be using two machines in this recipe. One will be the scanner machine and the other will be the server we want to scan.

Nmap is a great and widely available port scanner. Let's start by installing it on the scanner machine. You can install it from the repositories of most Linux distributions, from ports on BSD and from Homebrew on OS X. You can also download an installer for Windows from http://nmap.org/download.html.

How to do it...

Perform the following steps to verify your firewall by port scanning:

  1. On your scanner machine, open up a terminal window and type the following command (here,...

Turning off unnecessary services


The best way to avoid potential security issues with services you're not actively using is to disable them. This recipe will list the steps to identify the running system services that have open network ports and disable them.

How to do it...

Let's start by identifying the processes that open network ports on your systems. This can be done with the help of the following steps:

  1. Navigate to Others | Command Shell.

  2. Type in the command netstat -tulpen and click Execute command.

You will see a list of server processes with active network connections.

In the Local Address column, you will see entries such as 0.0.0.0:22. This means that a process is listening on port 22. The PID/Program name column will tell you which process is responsible for opening this port.

If you identify a process that you are not using and you know that it isn't essential to your system, you can disable it with the help of the following steps:

  1. Navigate to System | Bootup and Shutdown.

  2. Find the startup...

Verifying the strength of passwords


If you allow administrative users to log into your system using their username and password, your system is only as secure as the passwords used by those users. It's a good idea to periodically attempt to crack all the passwords on your system. If you find passwords that are easy to guess or crack through brute force, you should ask users to change them.

Getting ready

For this recipe, we will be using the password-cracking program called John the Ripper. Start by installing the package named john. Refer to the Installing software packages recipe from Chapter 1, Setting Up Your System, for more details.

How to do it...

John the Ripper tries to crack passwords by brute force, which means it will try every word and combination of characters. If any user on your system has a strong password (long and complex), John will not be able to crack it in a reasonable amount of time. You should let the cracking run for a couple of days and then decide that the remaining...

Disabling root login over SSH


Allowing the root user to log in over SSH is a potential security vulnerability. An attacker may try to break into your system by trying every password for the root user. It's recommended to disallow the root user's access over SSH and to log in as another user with the sudo privileges to perform administrative tasks.

How to do it...

Perform the following steps to disable root login:

  1. Navigate to Servers | SSH Server | Authentication.

  2. Answer No to the Allow login by root? question.

  3. Click Save.

  4. Back on the SSH Server module screen, click Apply Changes.

How it works...

Webmin updates the SSH configuration file (/etc/ssh/sshd_config) by setting PermitRootLogin to no. From now on, SSH will treat every password entered for the root user as incorrect.

Restricting Webmin access to a specific IP


The firewall is your first line of defense, but you should take additional precautions while running Webmin on an Internet-connected server. Webmin allows you to restrict access to a list of specific IP addresses and networks. It's a good idea to protect Webmin this way; otherwise, an attacker can try to guess your password and take over your system.

In this recipe, we will configure Webmin to accept connections only from your IP address.

Getting ready

Before you start, you should determine the IP address you are currently using to connect to Webmin. In order to do this, log into Webmin and navigate to Webmin | Webmin Users | View Login Sessions. Your active login session will be marked in bold and your address will be listed in the IP address column.

How to do it...

For restricting Webmin access, perform the following steps:

  1. Navigate to Webmin | Webmin Configuration | IP Access Control.

  2. Set Allowed IP addresses to Only allow from listed addresses.

  3. Enter...

Connecting to Webmin securely over an SSH tunnel


If your server is connected to the Internet and you use SSH to connect to it, you can secure it by disallowing Webmin from accepting any remote connections. You can then use an SSH tunnel to connect to Webmin. This lowers the potential attack surface of your machine and protects you against possible security vulnerabilities in Webmin itself. Any attacker would have to break into your SSH account or otherwise gain local access to your system to connect to Webmin.

Getting ready

Before you begin, you should follow the Restricting Webmin access to a specific IP recipe of this chapter and add the IP address 127.0.0.1 to the list of hosts allowed to connect to Webmin.

In this recipe, we'll be using the command line version of SSH that is available on most systems, but it is not available on Windows. Look in the There's more... section of this recipe for instructions specific to Windows.

How to do it...

Perform the following steps to securely connect...

Closing inactive Webmin sessions automatically


Webmin's login sessions are not set to expire by default. This causes a potential security risk. If a user leaves his or her computer unattended while logged into Webmin, an attacker could potentially use the situation to harm your system or disable its security. Fortunately, this situation is easily remedied by changing a Webmin setting.

How to do it...

Perform the following steps to close inactive Webmin sessions automatically:

  1. Navigate to Webmin | Webmin Configuration | Authentication.

  2. Tick the checkbox marked as Auto-logout and set the automatic logout to happen after 10 minutes of inactivity.

  3. Click Save.

How it works...

Webmin stores authentication options in its server configuration file (/etc/webmin/miniserv.conf by default). The line defining inactivity time after which users will be automatically logged out starts with the keyword logouttime and specifies the time in minutes. For instance, it may look like this:

logouttime=10

Whenever a client...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Webmin Administrator's Cookbook
Published in: Mar 2014Publisher: ISBN-13: 9781849515849
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Michal Karzynski

Michał Karzyński, with a scientific research background in the areas of molecular biology and bioinformatics, has been running Unix-like operating systems since 2002. He works as a web application developer, programming in dynamic languages such as JavaScript, Python, Perl, and PHP. He specializes in designing programming interfaces between servers and client applications based on the HTTP protocol. He has been using Webmin for over five years to assist in setting up and managing servers. He is currently employed as a project manager at the Gdańsk University of Technology in Poland. His blog can be found at http://michal.karzynski.pl.
Read more about Michal Karzynski