Created
October 6, 2016 12:15
-
-
Save arabcoders/4a60fed66faa0bbf740cdf081381068d to your computer and use it in GitHub Desktop.
generate ovpn file
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 | |
#Dir where easy-rsa is placed | |
EASY_RSA_DIR="/etc/openvpn/easy-rsa" | |
KEYS_DIR="$EASY_RSA_DIR/keys" | |
# Path to tls auth file. | |
TLS_AUTH_PATH="/etc/openvpn/ta.key" | |
# Dir where profiles will be placed | |
OVPN_PATH="/root/ovpn" | |
# VPN Remote Address. | |
REMOTE="ip address" | |
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 | |
proto udp | |
sndbuf 0 | |
rcvbuf 0 | |
keepalive 10 120 | |
remote $RMEOTE | |
resolv-retry infinite | |
nobind | |
persist-key | |
persist-tun | |
remote-cert-tls server | |
cipher AES-128-CBC | |
comp-lzo | |
setenv opt block-outside-dns | |
tls-auth [inline] 1 | |
verb 1 | |
<tls-auth> | |
`sed -n '/BEGIN/,$p' $TLS_AUTH_PATH` | |
</tls-auth> | |
<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