Created
December 28, 2016 09:49
-
-
Save ssinyagin/b196da5234c57de71bcfb44041274a15 to your computer and use it in GitHub Desktop.
Create OpenVPN client config with embedded certificates
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/sh | |
# FILE: /etc/openvpn/client_configs/mk_client.sh | |
CLIENT=$1 | |
if [ "$CLIENT" = "" ]; then | |
echo "missing client name" 1>&2 | |
exit | |
fi | |
CL_CRT=/etc/openvpn/easy-rsa/keys/${CLIENT}.crt | |
CL_KEY=/etc/openvpn/easy-rsa/keys/${CLIENT}.key | |
if [ ! -f $CL_CRT ]; then | |
echo "no such file: $CL_CRT" 1>&2 | |
exit | |
fi | |
if [ ! -f $CL_KEY ]; then | |
echo "no such file: $CL_KEY" 1>&2 | |
exit | |
fi | |
CONF=${CLIENT}.conf | |
cat base_conf > $CONF | |
echo "<ca>" >> $CONF | |
cat /etc/openvpn/easy-rsa/keys/ca.crt | \ | |
grep -A 100 "BEGIN CERTIFICATE" | \ | |
grep -B 100 "END CERTIFICATE" >> $CONF | |
echo "</ca>" >> $CONF | |
echo "<cert>" >> $CONF | |
cat $CL_CRT | \ | |
grep -A 100 "BEGIN CERTIFICATE" | \ | |
grep -B 100 "END CERTIFICATE" >> $CONF | |
echo "</cert>" >> $CONF | |
echo "<key>" >> $CONF | |
cat $CL_KEY | \ | |
grep -A 100 "BEGIN PRIVATE KEY" | \ | |
grep -B 100 "END PRIVATE KEY" >> $CONF | |
echo "</key>" >> $CONF |
base_conf="/etc/openvpn/server.conf"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cat: base_conf: No such file or directory