Skip to content

Instantly share code, notes, and snippets.

@valentt
Last active October 5, 2017 10:14
Show Gist options
  • Save valentt/8829fe66b4351d2ab1e6554f97ab2ba1 to your computer and use it in GitHub Desktop.
Save valentt/8829fe66b4351d2ab1e6554f97ab2ba1 to your computer and use it in GitHub Desktop.
Script for creating Openvpn config files for Windows
#!/bin/bash
#Dir where easy-rsa is placed
EASY_RSA_DIR="/etc/openvpn/easy-rsa/2.0"
KEYS_DIR="$EASY_RSA_DIR/keys"
# Dir where profiles will be placed
OVPN_PATH="/etc/openvpn/easy-rsa/2.0/keys"
REMOTE="YOUR-vpn-SERVER.com 1194"
if [ -z "$1" ]
then
echo -n "Enter new client common name (CN): "
read -e CN
else
CN=$1
fi
if [ -z "$CN" ]
then echo "You must provide a CN."
exit
fi
cd $EASY_RSA_DIR
if [ -f $KEYS_DIR/$CN.crt ]
then
echo "Certificate with the CN $CN already exists!"
echo " $KEYS_DIR/$CN.crt"
else
source ./vars > /dev/null
./pkitool $CN
fi
cat > $OVPN_PATH/${CN}.ovpn << END
client
dev tun
resolv-retry infinite
nobind
persist-key
persist-tun
verb 1
comp-lzo
proto udp
remote $REMOTE
<ca>
`cat $KEYS_DIR/ca.crt`
</ca>
<cert>
`sed -n '/BEGIN/,$p' $KEYS_DIR/${CN}.crt`
</cert>
<key>
`cat $KEYS_DIR/${CN}.key`
</key>
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment