#!/bin/bash # Create OVPN Client # Default Variable Declarations DEFAULT="Default.txt" FILEEXT=".ovpn" CRT=".crt" OKEY=".key" KEY=".3des.key" CA="ca.crt" TA="ta.key" INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER) echo "Please enter a Name for the Client:" read NAME #Build the client key and then encrypt the key cd /etc/openvpn/easy-rsa source /etc/openvpn/easy-rsa/vars ./build-key-pass $NAME cd keys openssl rsa -in $NAME$OKEY -des3 -out $NAME$KEY #1st Verify that clients Public Key Exists if [ ! -f $NAME$CRT ]; then echo "[ERROR]: Client Public Key Certificate not found: $NAME$CRT" exit fi echo "Client's cert found: $NAME$CRT" #Then, verify that there is a private key for that client if [ ! -f $NAME$KEY ]; then echo "[ERROR]: Client 3des Private Key not found: $NAME$KEY" exit fi echo "Client's Private Key found: $NAME$KEY" #Confirm the CA public key exists if [ ! -f $CA ]; then echo "[ERROR]: CA Public Key not found: $CA" exit fi echo "CA public Key found: $CA" #Confirm the tls-auth ta key file exists if [ ! -f $TA ]; then echo "[ERROR]: tls-auth Key not found: $TA" exit fi echo "tls-auth Private Key found: $TA" #Ready to make a new .ovpn file - Start by populating with the #default file cat $DEFAULT > $NAME$FILEEXT #Now, append the CA Public Cert echo "" >> $NAME$FILEEXT cat $CA >> $NAME$FILEEXT echo "" >> $NAME$FILEEXT #Next append the client Public Cert echo "" >> $NAME$FILEEXT cat $NAME$CRT | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' >> $NAME$FILEEXT echo "" >> $NAME$FILEEXT #Then, append the client Private Key echo "" >> $NAME$FILEEXT cat $NAME$KEY >> $NAME$FILEEXT echo "" >> $NAME$FILEEXT #Finally, append the TA Private Key echo "" >> $NAME$FILEEXT cat $TA >> $NAME$FILEEXT echo "" >> $NAME$FILEEXT # Copy the .ovpn profile to the home directory for convenient remote access cp /etc/openvpn/easy-rsa/keys/$NAME$FILEEXT /home/$INSTALL_USER/ovpns/$NAME$FILEEXT echo "$NAME$FILEEXT moved to home directory." whiptail --title "MakeOVPN" --msgbox "Done! $NAME$FILEEXT successfully created and \ moved to directory /home/$INSTALL_USER/ovpns." 8 78 # Original script written by Eric Jodoin.