DEV Community

Eastern Dev
Eastern Dev

Posted on

How I Automated VPN Deployment: A Step-by-Step Guide

How I Automated VPN Deployment: A Step-by-Step Guide

I needed a VPN. I did not want to pay a monthly subscription. So I built one.

And then I automated the entire process.

Why Build Your Own VPN?

Commercial VPNs have problems:

  • They cost $5-15/month
  • They log your data (despite claiming otherwise)
  • They are controlled by companies you do not know
  • They can be blocked by governments

A self-hosted VPN solves all of these.

The Stack

  • Outline VPN — Open-source, easy to set up
  • Cloud VPS — Any cheap provider ($3-5/month)
  • Docker — For containerization
  • Shell scripts — For automation

Step 1: Get a VPS

I used a minimal Ubuntu 22.04 VPS. Cost: $3.50/month.

ssh root@your-server-ip
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Outline VPN

sudo bash -c "$(wget -qO- https://raw.githubusercontent.com/Jigsaw-Code/outline-server/master/src/server_manager/install_scripts/install_outline_server.sh)"
Enter fullscreen mode Exit fullscreen mode

This gives you:

  • An API port
  • A management URL
  • Access keys

Step 3: Automate with Docker

FROM ubuntu:22.04
RUN apt-get update && apt-get install -y wget curl
RUN bash -c "$(wget -qO- https://raw.githubusercontent.com/Jigsaw-Code/outline-server/master/src/server_manager/install_scripts/install_outline_server.sh)"
EXPOSE 443 6379
Enter fullscreen mode Exit fullscreen mode

Step 4: Auto-Renewal Script

#!/bin/bash
# vpn-health-check.sh
if ! curl -s http://localhost:6379 > /dev/null; then
  echo "VPN down! Restarting..."
  docker restart outline-server
  echo "VPN restarted at $(date)" >> /var/log/vpn-monitor.log
fi
Enter fullscreen mode Exit fullscreen mode

Add to crontab:

echo "*/5 * * * * /root/vpn-health-check.sh" | crontab -
Enter fullscreen mode Exit fullscreen mode

Step 5: Deploy with Surge.sh

I also built a landing page for sharing VPN access:

npm install -g surge
surge ./vpn-page https://ai-vpn-kit.surge.sh/ --token YOUR_TOKEN
Enter fullscreen mode Exit fullscreen mode

Check it out: AI VPN Kit

The Full Automated Pipeline

  1. VPS boots → Outline installs automatically
  2. Health check every 5 minutes
  3. Auto-restart on failure
  4. Access keys generated and shared via secure page
  5. Zero manual intervention

Cost Comparison

Solution Monthly Cost Your Data
NordVPN $12.99 They see it
ExpressVPN $12.95 They see it
Self-hosted $3.50 Only you

What I Learned

Automation is not about saving time. It is about eliminating the need for trust.

When your VPN runs itself, you do not need to trust a company. You only need to trust your code.


Want more automation guides? Visit my store where I sell AI-created methodologies and tools.

BTC: bc1qj03dpcmylkgq0rar0r689r69c2nmh9qdp3uwmp

Follow on Dev.to

Top comments (0)