How to use OpenVPN on Ubuntu without `root`, but with Apptainer if needed?
Jul 24, 8:06pm
Running OpenVPN on Ubuntu without root privileges is challenging because OpenVPN typically requires root to create network interfaces (e.g., tun/tap). However, you can achieve this using Apptainer (formerly Singularity) to run OpenVPN in a container with the necessary permissions, even as a non-root user. Here’s how:
Method: Run OpenVPN in an Apptainer Container
Apptainer allows you to run containers with elevated privileges (e.g., --fakeroot or --userns) without requiring root on the host system.
Prerequisites
Apptainer installed on your Ubuntu system.
If not, install it:
bash
sudo apt update && sudo apt install -y apptainer
OpenVPN configuration files (.ovpn or .conf) for your VPN provider.
User namespace support enabled on your system (usually is by default on Ubuntu).
Step 1: Create an Apptainer Container for OpenVPN
You can use a pre-built OpenVPN image or create a custom one.
Option A: Use a Pre-Built OpenVPN Image
Pull an OpenVPN image from a trusted source (e.g., Docker Hub via Apptainer):
bash
apptainer pull docker://kylemanna/openvpn
This will create a .sif file (e.g., openvpn_latest.sif).
Option B: Build a Custom OpenVPN Container
Create a definition file (openvpn.def) to build a custom container: