Created
February 14, 2019 16:53
-
-
Save tomazursic/ff855e6c8ca3c83ef4f2209619afe0b6 to your computer and use it in GitHub Desktop.
Generate OpenVPN keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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