-
Initial Server Access
-
Basic Security
- Update system packages
- Configure firewall (UFW)
- Install and configure fail2ban
- Set up automatic security updates
-
Server Configuration
- Set timezone
- Install other utilities (htop, tmux, etc.)
-
Install Docker
- Install Docker & Docker Compose
- Add user to docker group
# local
ssh root@<server_IPv4># server
adduser <username>
usermod -aG sudo <username># local
ssh-copy-id -i ~/.ssh/<key_name> <username>@<server_IPv4># server
sudo nano /etc/ssh/sshd_config
# edit ->
# PasswordAuthentication no
# UsePAM no
# PermitRootLogin no
sudo systemctl reload sshNota: Para acceder de nuevo al servidor es posible que sea necesario agregar la clave SSH al agente ssh. Otra forma es acceder utilizando el nombre de usuario y la clave privada.
ssh -i ~/.ssh/<key_name> <username>@<server_IPv4># server
sudo nano /etc/ssh/sshd_config
# edit ->
# -- Forced disconnection after a certain inactivity (300 seconds)
# ClientAliveInterval 300
# ClientAliveCountMax 1
# -- Automatic disconnection in case of incorrect login
# MaxAuthTries 3
# -- Deactivate unused functions
# AllowTcpForwarding no # Disables port forwarding.
# X11Forwarding no # Disables remote GUI view.
# AllowAgentForwarding no # Disables the forwarding of the SSH login.
sudo systemctl restart ssh# server
sudo apt update && sudo apt upgrade -yUFW (Uncomplicated FireWall) already comes installed with Ubuntu
# server
sudo ufw default deny incoming
sudo ufw default allow outgoingCaution
If SSH is not allowed, the server will not be accessible.
# server
sudo ufw allow OpenSSH# server
sudo ufw enable
sudo ufw status # check statusNOTE: Docker overrides some UFW rules and containers can still be accessible although UFW rules block that port. To avoid that use Reverse Proxy (step 5).
# server
sudo apt install fail2ban -y
sudo systemctl enable fail2ban# server
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.localNOTE: Usually already installed in Ubuntu Server.
# server
sudo apt install unattended-upgrades -y
systemctl status unattended-upgrades # Check running status# server
sudo timedatectl set-timezone <timezone>Follow installation guides
Follow docs: https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
# server
sudo usermod -aG docker <username>