<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Riefqi Destiady</title>
    <description>The latest articles on DEV Community by Riefqi Destiady (@riefqid).</description>
    <link>https://dev.to/riefqid</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4242005%2F58c6fda9-4c9b-4a0a-aec8-d013a979326f.jpg</url>
      <title>DEV Community: Riefqi Destiady</title>
      <link>https://dev.to/riefqid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/riefqid"/>
    <language>en</language>
    <item>
      <title>Production VPS Setup in 15 Minutes: Docker + UFW + Fail2ban + Auto-Updates</title>
      <dc:creator>Riefqi Destiady</dc:creator>
      <pubDate>Mon, 16 Nov 2026 05:39:25 +0000</pubDate>
      <link>https://dev.to/riefqid/production-vps-setup-in-15-minutes-docker-ufw-fail2ban-auto-updates-1lac</link>
      <guid>https://dev.to/riefqid/production-vps-setup-in-15-minutes-docker-ufw-fail2ban-auto-updates-1lac</guid>
      <description>&lt;p&gt;I once spun up a new VPS, installed Docker, deployed an app, and forgot the firewall. Two days later the logs were full of SSH brute-force attempts. Lesson learned: &lt;strong&gt;default VPS is not secure&lt;/strong&gt;. Docker also exposes ports to the world by default.&lt;/p&gt;

&lt;p&gt;This article is the checklist I use every time I provision a fresh VPS. 15 minutes, done. Works for homelab, side projects, or small production.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fresh Ubuntu 24.04 LTS VPS (any provider)&lt;/li&gt;
&lt;li&gt;SSH key ready (no password login)&lt;/li&gt;
&lt;li&gt;Domain optional (for SSL later)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Recommended:&lt;/strong&gt; &lt;a href="https://m.do.co/c/3003e30594de" rel="noopener noreferrer"&gt;DigitalOcean&lt;/a&gt; — $200 credit for new accounts&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1: User &amp;amp; SSH Hardening
&lt;/h2&gt;

&lt;p&gt;Login as root, create a non-root user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;adduser deploy
usermod -aG sudo deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy SSH key to the new user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p /home/deploy/.ssh
cp /root/.ssh/authorized_keys /home/deploy/.ssh/
chown -R deploy:deploy /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
chmod 600 /home/deploy/.ssh/authorized_keys
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test login as &lt;code&gt;deploy&lt;/code&gt; in a new terminal. If it works, harden SSH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano /etc/ssh/sshd_config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change/uncomment these lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart SSH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl reload sshd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 2: UFW Firewall
&lt;/h2&gt;

&lt;p&gt;Default deny incoming, allow outgoing. Only open what you need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ufw default deny incoming
ufw default allow outgoing

&lt;span class="c"&gt;# SSH (port 22) - change if using custom port&lt;/span&gt;
ufw allow 22/tcp

&lt;span class="c"&gt;# HTTP/HTTPS for web&lt;/span&gt;
ufw allow 80/tcp
ufw allow 443/tcp

&lt;span class="c"&gt;# Docker internal (optional, if containers need to talk)&lt;/span&gt;
&lt;span class="c"&gt;# ufw allow from 172.17.0.0/16&lt;/span&gt;

&lt;span class="c"&gt;# Enable&lt;/span&gt;
ufw &lt;span class="nb"&gt;enable&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ufw status verbose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 3: Fail2ban
&lt;/h2&gt;

&lt;p&gt;Block IPs that repeatedly fail login. Install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt install -y fail2ban
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create custom config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano /etc/fail2ban/jail.local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[DEFAULT]&lt;/span&gt;
&lt;span class="na"&gt;bantime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt;
&lt;span class="na"&gt;findtime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;
&lt;span class="na"&gt;maxretry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="na"&gt;backend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;systemd&lt;/span&gt;

&lt;span class="k"&gt;[sshd]&lt;/span&gt;
&lt;span class="na"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ssh&lt;/span&gt;
&lt;span class="na"&gt;filter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sshd&lt;/span&gt;
&lt;span class="na"&gt;logpath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;
&lt;span class="na"&gt;maxretry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;

&lt;span class="k"&gt;[docker-auth]&lt;/span&gt;
&lt;span class="na"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2375&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2376&lt;/span&gt;
&lt;span class="na"&gt;filter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;docker&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;
&lt;span class="na"&gt;logpath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;
&lt;span class="na"&gt;maxretry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; --now fail2ban
fail2ban-client status sshd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 4: Docker + Docker Compose
&lt;/h2&gt;

&lt;p&gt;Install from official repo (not apt default which can be outdated):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Remove old versions&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; pkg &lt;span class="k"&gt;in&lt;/span&gt; docker.io docker-doc docker-compose podman-docker containerd runc&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    apt remove -y &lt;span class="nv"&gt;$pkg&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;

&lt;span class="c"&gt;# Install dependencies&lt;/span&gt;
apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt install -y ca-certificates curl gnupg lsb-release

&lt;span class="c"&gt;# Add Docker GPG key&lt;/span&gt;
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg &lt;span class="o"&gt;|&lt;/span&gt; gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg

&lt;span class="c"&gt;# Add repository&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; \
  &lt;span class="s2"&gt;"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release &amp;amp;&amp;amp; echo "&lt;/span&gt;&lt;span class="nv"&gt;$VERSION_CODENAME&lt;/span&gt;&lt;span class="s2"&gt;") stable"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; \
  tee /etc/apt/sources.list.d/docker.list &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null

&lt;span class="c"&gt;# Install&lt;/span&gt;
apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add user to docker group:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;usermod -aG docker deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test (logout/login first, or &lt;code&gt;newgrp docker&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run --rm hello-world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 5: Automatic Security Updates
&lt;/h2&gt;

&lt;p&gt;Production servers need patches without manual intervention:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apt install -y unattended-upgrades needrestart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano /etc/apt/apt.conf.d/50unattended-upgrades
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure these are uncommented:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Unattended-Upgrade::Allowed-Origins {
    "${distro_id}:${distro_codename}-security";
    "${distro_id}:${distro_codename}-updates";
};
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
Unattended-Upgrade::MinimalSteps "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "false";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enable timer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; --now unattended-upgrades
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tail -f /var/log/unattended-upgrades/unattended-upgrades.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 6: Verification &amp;amp; Test
&lt;/h2&gt;

&lt;p&gt;Post-setup checklist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. SSH key-only&lt;/span&gt;
ssh -o &lt;span class="nv"&gt;PasswordAuthentication&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;no deploy@&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;IP&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;# 2. Firewall active&lt;/span&gt;
ufw status

&lt;span class="c"&gt;# 3. Fail2ban running&lt;/span&gt;
fail2ban-client status sshd

&lt;span class="c"&gt;# 4. Docker working&lt;/span&gt;
docker version
docker compose version

&lt;span class="c"&gt;# 5. Auto-updates enabled&lt;/span&gt;
systemctl status unattended-upgrades

&lt;span class="c"&gt;# 6. Open ports from outside (should only be 22, 80, 443)&lt;/span&gt;
nmap -sS &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;IP&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Bonus: One-Liner Setup Script
&lt;/h2&gt;

&lt;p&gt;Save this as a GitHub Gist, then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -fsSL https://gist.githubusercontent.com/&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;your-username&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;gist-id&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/raw/setup-vps.sh &lt;span class="o"&gt;|&lt;/span&gt; bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Script content (&lt;code&gt;setup-vps.sh&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -euo pipefail

&lt;span class="nv"&gt;USERNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"deploy"&lt;/span&gt;
&lt;span class="nv"&gt;SSH_PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"22"&lt;/span&gt;

&lt;span class="c"&gt;# 1. Create user&lt;/span&gt;
adduser --disabled-password --gecos &lt;span class="s2"&gt;""&lt;/span&gt; &lt;span class="s2"&gt;"$USERNAME"&lt;/span&gt;
usermod -aG sudo &lt;span class="s2"&gt;"$USERNAME"&lt;/span&gt;

&lt;span class="c"&gt;# 2. SSH hardening&lt;/span&gt;
mkdir -p &lt;span class="s2"&gt;"/home/$USERNAME/.ssh"&lt;/span&gt;
cp /root/.ssh/authorized_keys &lt;span class="s2"&gt;"/home/$USERNAME/.ssh/"&lt;/span&gt;
chown -R &lt;span class="s2"&gt;"$USERNAME:$USERNAME"&lt;/span&gt; &lt;span class="s2"&gt;"/home/$USERNAME/.ssh"&lt;/span&gt;
chmod 700 &lt;span class="s2"&gt;"/home/$USERNAME/.ssh"&lt;/span&gt;
chmod 600 &lt;span class="s2"&gt;"/home/$USERNAME/.ssh/authorized_keys"&lt;/span&gt;

cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/ssh/sshd_config.d/99-hardening.conf &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;EOF
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
Port &lt;span class="nv"&gt;$SSH_PORT&lt;/span&gt;
EOF
systemctl reload sshd

&lt;span class="c"&gt;# 3. UFW&lt;/span&gt;
ufw default deny incoming
ufw default allow outgoing
ufw allow &lt;span class="s2"&gt;"$SSH_PORT"&lt;/span&gt;/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force &lt;span class="nb"&gt;enable&lt;/span&gt;

&lt;span class="c"&gt;# 4. Fail2ban&lt;/span&gt;
apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt install -y fail2ban
cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/fail2ban/jail.local &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;EOF
&lt;span class="o"&gt;[&lt;/span&gt;DEFAULT&lt;span class="o"&gt;]&lt;/span&gt;
bantime &lt;span class="o"&gt;=&lt;/span&gt; 3600
findtime &lt;span class="o"&gt;=&lt;/span&gt; 600
maxretry &lt;span class="o"&gt;=&lt;/span&gt; 3
backend &lt;span class="o"&gt;=&lt;/span&gt; systemd

&lt;span class="o"&gt;[&lt;/span&gt;sshd&lt;span class="o"&gt;]&lt;/span&gt;
enabled &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
port &lt;span class="o"&gt;=&lt;/span&gt; ssh
filter &lt;span class="o"&gt;=&lt;/span&gt; sshd
logpath &lt;span class="o"&gt;=&lt;/span&gt; /var/log/auth.log
maxretry &lt;span class="o"&gt;=&lt;/span&gt; 3
EOF
systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; --now fail2ban

&lt;span class="c"&gt;# 5. Docker&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; pkg &lt;span class="k"&gt;in&lt;/span&gt; docker.io docker-doc docker-compose podman-docker containerd runc&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    apt remove -y &lt;span class="nv"&gt;$pkg&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt install -y ca-certificates curl gnupg lsb-release
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg &lt;span class="o"&gt;|&lt;/span&gt; gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release &amp;amp;&amp;amp; echo "&lt;/span&gt;&lt;span class="nv"&gt;$VERSION_CODENAME&lt;/span&gt;&lt;span class="s2"&gt;") stable"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; tee /etc/apt/sources.list.d/docker.list &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null
apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
usermod -aG docker &lt;span class="s2"&gt;"$USERNAME"&lt;/span&gt;

&lt;span class="c"&gt;# 6. Auto-update&lt;/span&gt;
apt install -y unattended-upgrades needrestart
cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/apt/apt.conf.d/50unattended-upgrades &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;EOF
Unattended-Upgrade::Allowed-Origins &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"\${distro_id}:\${distro_codename}-security"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="s2"&gt;"\${distro_id}:\${distro_codename}-updates"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
Unattended-Upgrade::AutoFixInterruptedDpkg &lt;span class="s2"&gt;"true"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
Unattended-Upgrade::MinimalSteps &lt;span class="s2"&gt;"true"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
Unattended-Upgrade::Remove-Unused-Dependencies &lt;span class="s2"&gt;"true"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
Unattended-Upgrade::Automatic-Reboot &lt;span class="s2"&gt;"false"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
EOF
systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; --now unattended-upgrades

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Setup complete. Login as $USERNAME and test docker."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;This is the foundation. Next articles in this series:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker Compose production template (PostgreSQL + Redis + Nginx + Backup)&lt;/li&gt;
&lt;li&gt;Monitoring stack: Prometheus + Grafana + Loki&lt;/li&gt;
&lt;li&gt;CI/CD with GitHub Actions + Docker&lt;/li&gt;
&lt;li&gt;Zero-downtime deployments&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Part of the "Production Infrastructure for Developers" series.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vps</category>
      <category>linux</category>
      <category>devops</category>
      <category>security</category>
    </item>
  </channel>
</rss>
