Skip to content

Instantly share code, notes, and snippets.

@tomazursic
Created February 14, 2019 16:53
Show Gist options
  • Save tomazursic/ff855e6c8ca3c83ef4f2209619afe0b6 to your computer and use it in GitHub Desktop.
Save tomazursic/ff855e6c8ca3c83ef4f2209619afe0b6 to your computer and use it in GitHub Desktop.
Generate OpenVPN keys
#!/bin/bash
# Current file directory path
DIR="$(cd "$(dirname "$0")" && pwd)"
cd $DIR
generate_keys () {
key_dir=keys
archive=client-$ID.zip
base_config=base-client.conf
source ./vars && ./pkitool $ID && \
cat ${base_config} \
<(echo -e '<ca>') \
${key_dir}/ca.crt \
<(echo -e '</ca>\n<cert>') \
${key_dir}/$ID.crt \
<(echo -e '</cert>\n<key>') \
${key_dir}/$ID.key \
<(echo -e '</key>\n<tls-auth>') \
${key_dir}/ta.key \
<(echo -e '</tls-auth>') \
> ${key_dir}/$ID.ovpn && \
if [ ! -e $archive ]; then
zip -r $archive ${key_dir}/$ID.crt \
${key_dir}/$ID.key ${key_dir}/$ID.ovpn\
else
echo "Nothing to do! $archive exist"
fi
}
usage() {
echo -e "Generate new client vpn keys\n"
echo "Usage:"
echo "./newclient <client-identifier> - Generate new client keys"
}
main() {
ID=$1
if [[ -z "$ID" ]]; then
usage
exit 1
else
generate_keys
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment