Create a Public Key Infrastructure Using the easy-rsa Scripts

<< back to OpenVPN

The first step to setup a OpenVPN server is to create a PKI (Public Key Infrastructure) from scratch. It consists of


 * A public master Certificate Authority (CA) certificate and a private key
 * A separate public certificate and private key pair (hereafter referred to as a certificate) for each server and each client.

We could use easy-rsa scripts to do this. Install it by running

Creating certificates
To keep creating process separated, we could copy scripts to different place every time to do the job.

change direcoty

To ensure the consistent use of values when generating the PKI, set default values to be used by the PKI generating scripts. Edit /root/easy-rsa/vars and at a minimum set the parameters (do not leave any of these parameters blank). Change the KEY_SIZE parameter to 2048 for the SSL/TLS to use 2048bit RSA keys for authentication.
 * KEY_COUNTRY
 * KEY_PROVINCE
 * KEY_CITY
 * KEY_ORG
 * KEY_EMAIL

Export the environment variables.

Delete any previously created certificates.

The build-ca script generates the Certificate Authority (CA) certificate.

The build-key-server script  generates a server certificate. Make sure that the server name (Common Name when running the script) is unique.

The build-dh script generates the Diffie-Hellman parameters .pem file needed by the server.

The build-key script  generates a client certificate. Make sure that the client name (Common Name when running the script) is unique.

Generate a secret Hash-based Message Authentication Code (HMAC) by running

And now, you can go on to setup the server configuration.