Skip to content

Instantly share code, notes, and snippets.

@dmytro
Last active March 19, 2023 12:21
Show Gist options
  • Save dmytro/0606cb32e42fc0918466 to your computer and use it in GitHub Desktop.
Save dmytro/0606cb32e42fc0918466 to your computer and use it in GitHub Desktop.
Script for OpenVPN generate client config file.
#!/bin/bash
# Easy script to create OpenVPN client configuration with the user, pre-generating user's
# RSA key and certificate.
#
# Configuration template must exist in the same directory, with only missing part: certificates.
#
# (c) Dmytro Kovalov, 2015
#
cd $(dirname ${BASH_SOURCE[0]})
read -p "Please type in user name for the new config: " USER
[ -z ${USER} ] && { echo "Cannot be empty"; exit 1; }
[ -f keys/${USER}.crt ] && { echo "Certificate keys/${USER}.crt already exists"; exit 2; }
source ./vars
./build-key ${USER}
(
# This should be existing config template, with only missing certificates, and keys sections.
cat config.ovpn.tpl
echo '<key>'
cat keys/${USER}.key
echo '</key>'
echo '<cert>'
cat keys/${USER}.crt
echo '</cert>'
echo '<ca>'
cat keys/ca.crt
echo '</ca>'
) > openvpn_${USER}.ovpn
@RichardBronosky
Copy link

To convert an existing 4 file (ovpn, ca, key, crt) to a single unified/embedded ovpn file see https://gist.github.com/RichardBronosky/331f975bba6697e5a15217233d280c06

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