Skip to content

Instantly share code, notes, and snippets.

@akxcix
Created May 6, 2023 00:42
Show Gist options
  • Save akxcix/935e588dad2b920606497e708fd06151 to your computer and use it in GitHub Desktop.
Save akxcix/935e588dad2b920606497e708fd06151 to your computer and use it in GitHub Desktop.

OpenVPN

What you need

  • a server on a cloud (anything works, i have been using the cheapest DO droplet)
  • docker on that vm

Steps

# pull image from dockerhub
docker pull kylemanna/openvpn

# create a directory to store configs
mkdir ~/openvpn-data

# initialize config. set `YOUR_PUBLIC_IP_ADDRESS` with server's public IP
docker run -v ~/openvpn-data:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://YOUR_PUBLIC_IP_ADDRESS

# generate keys and certificates. you will be prompted for a passphrase, keep 
# it safe and handy
docker run -v ~/openvpn-data:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki

# start server in a docker container
docker run -v ~/openvpn-data:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn

# create client config file. replace `CLIENT_NAME` with what you want to name it
docker run -v ~/openvpn-data:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full CLIENT_NAME nopass
docker run -v ~/openvpn-data:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient CLIENT_NAME > CLIENT_NAME.ovpn

This whole process gets you an OpenVPN server container up and running using docker, and in the end you get your CLIENT_NAME.ovpn config which you would need for connecting to the server using OpenVPN clients. I am using tunnelblick on mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment