Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save erdoukki/1213e7573b9b902cb54f5ba5b82ea7df to your computer and use it in GitHub Desktop.
Save erdoukki/1213e7573b9b902cb54f5ba5b82ea7df 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment