Skip to content

Instantly share code, notes, and snippets.

@beebird
Forked from dmytro/generate_openvpn_config.sh
Created August 1, 2019 07:48
Show Gist options
  • Save beebird/45f59b0f6f40b48449876cba848232d7 to your computer and use it in GitHub Desktop.
Save beebird/45f59b0f6f40b48449876cba848232d7 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