Automatic OpenVPN User Creation with Email Alert
Normally, what we do is:
easy-rsacommandline tool to generate the
.keyfiles and the
- copy the required files to the desktop using WinSCP or FileZilla or any other software.
The above seems very tedious task to perform manually everytime a user ID has to be created. In this blog post, I’ll share a Shell Script to automate this process, as well as send an email with a
.zip file attached, containing all the relevant files.
I am assuming the following is already in place:
- OpenVPN Server on Linux (Version
OpenVPN 2.3.6 x86_64-redhat-linux-gnu)
- Easy RSA 3
Amazon Linux AMI 2016.03
The script uses the following command line tools to work:
- zip (to zip all the necessary files)
- mutt (to send email with attachment)
./createvpnuser.sh "OpenVPN User" [To Email ID (without spaces)]
The script works in the following way:
- The script takes 2 arguments for userID and email address, respectively.
- Password of the user is generated using
/dev/urandom, which is a pseudo random number generator.
./easyrsa build-client-full <USERID> nopasscommand is used to generate the required files.
- The files are zipped to a predefined location.
- An email is sent to address given in Step 1.
- The above works for me. Cannot guarantee for you.
- Go through the script carefully before executing.
- You can download the
easyrsafile from Github (link below).
- Happy to help in any issues.