TOP
EN EL
Preparing and Securing an Ubuntu Server for Docker Installation
25 August 2024 Published by Aristotelis Pitaridis
Tools used for this tutorial
Ubuntu Server 24.04
SHARE

Introduction

Setting up an Ubuntu server for Docker involves several critical steps to ensure the server is secure and ready for container deployment. This guide will walk you through the process of preparing and securing your Ubuntu server, covering everything from initial setup to security best practices.

Step 1: Update and Upgrade the System

Before installing any new software, it’s essential to update your package lists and upgrade your existing packages to ensure you have the latest security patches.

sudo apt update
sudo apt upgrade -y

Step 2: Create a New User

For security reasons, it’s best not to use the root account for daily operations. Create a new user with sudo privileges.

sudo adduser newuser
sudo usermod -aG sudo newuser

Step 3: Secure SSH Access

Disable Root Login: Edit the SSH configuration file to disable root login.

sudo nano /etc/ssh/sshd_config

Find the line PermitRootLogin and change it to no.

Change the Default SSH Port: Changing the default SSH port can help reduce the risk of automated attacks.

sudo nano /etc/ssh/sshd_config

Change the line #Port 22 to a port number of your choice, e.g., Port 2222.

Restart SSH Service:

sudo systemctl restart sshd

Step 4: Install Firewall and Configure UFW

A firewall is crucial for securing your server. Install UFW (Uncomplicated Firewall) and configure it to allow only necessary traffic.

sudo apt install ufw
sudo ufw allow 2222/tcp  # Replace 2222 with your chosen SSH port
sudo ufw allow 80/tcp    # Allow HTTP traffic
sudo ufw allow 443/tcp   # Allow HTTPS traffic
sudo ufw enable

Now that your server is secure, you can proceed with installing Docker.

Summary

This article provides a comprehensive guide on preparing and securing an Ubuntu server for Docker installation. It covers updating the system, creating a new user, securing SSH access, configuring a firewall, and installing Docker. Following these steps ensures your server is secure and ready for container deployment.