Creating a Client VPN Setup using OpenVPN

Before we begin I want to clearly identify the scope of this tutorial. There are different types of VPN, we will be creating a Client VPN which implies a many to one relationship. We will have multiple clients connecting via VPN to a single OpenVPN server. This OpenVPN server will assign IP addresses to each successfully authenticated client. Using this IP Address, client’s may, depending on your network security, access devices on a private network. Effectively appearning as if the Client was directly tied into the Private Network. If you are looking for a site-to-site VPN tunnel via IPSEC this is out of the scope of this tutorial.

Our Simple Client VPN Topology



We are assuming that the 172.16.23.0/24 network has the appropriate ACLs to the resources you want VPN Clients to access.

  1. Install the base packages needed

  2. Copy example confs

  3. For Ubuntu 12.04 64-bit, there is an issue with the scripts installed with openvpn.

    To fix create a symbolic link for openssl.cnf file that CA scripts look for.

  4. Change vars settings to your paticular set up.

  5. Create our Certificate Authority:

    This step is necessary to create a root level trusted authority that will sign the SSL certificates/keys used by both our OpenVPN server and OpenVPN clients, during their SSL handshake. If their is no trust between either entity, their will be a SSL invalid issue, because the client trying to connect is not presenting a trusted and signed certificate. For more information on SSL please see here.

  6. Create Server Cert and Key, signed by CA:

    Notice, in the next step, how we are signing the OpenVPN server’s Certificate and Key with our Certificate Authority certificate from the previous step!

  7. Create Client Certificate/Key Pair and sign by CA:

    Generating a 2048 bit RSA private key
    …………………..+++
    ……………….+++
    writing new private key to ‘thejimmahknows_vpnclient.key’
    —–
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter ‘.’, the field will be left blank.
    —–
    Country Name (2 letter code) [US]:
    State or Province Name (full name) [CT]:
    Locality Name (eg, city) [Hartford]:
    Organization Name (eg, company) [THEJIMMAHKNOWS]:
    Organizational Unit Name (eg, section) [changeme]:
    Common Name (eg, your name or your server’s hostname) [thejimmahknows_vpnclient]:
    Name [changeme]:jim
    Email Address [mail@host.domain]:

    Please enter the following ‘extra’ attributes
    to be sent with your certificate request
    A challenge password []:
    An optional company name []:
    Using configuration from /etc/openvpn/easy-rsa/openssl.cnf
    Check that the request matches the signature
    Signature ok
    The Subject’s Distinguished Name is as follows
    countryName :PRINTABLE:’US’
    stateOrProvinceName :PRINTABLE:’CT’
    localityName :PRINTABLE:’Hartford’
    organizationName :PRINTABLE:’THEJIMMAHKNOWS’
    organizationalUnitName:PRINTABLE:’changeme’
    commonName :T61STRING:’thejimmahknows_vpnclient’
    name :PRINTABLE:’jim’
    emailAddress :IA5STRING:’mail@host.domain’
    Certificate is to be certified until Nov 13 19:24:19 2022 GMT (3650 days)
    Sign the certificate? [y/n]:y

    1 out of 1 certificate requests certified, commit? [y/n]y
    Write out database with 1 new entries
    Data Base Updated

  8. Create Diffie Hellman Key Exchange:

  9. Change to Keys Directory

    So we just created a Certificate Authority certificate and key pair, a Server certificate and key pair signed by our CA, and a Client certificate and key pair signed by our CA. The scripts you just ran place the certificates and keys in the /etc/openvpn/easy-rsa/keys directory . Navitgate to this directory. You may notice that you need to be root user in order to change to this directory…Don’t worry that is a good thing! Do an ls -l so we can see what’s in this directory…we should see the following:

    NOTICE: We have to files per entity. a CRT and a KEY, it is very important that the KEY is only readable at the root level and only resides on the entity. You should not, I repeat not have the entity’s KEY in multiple locations.!!

  10. Copy Client files to Client device

    Copy the Client’s CRT and KEY to it’s device. You will also need to copy the ca.crt certificate to the Client’s device. (This is due to the fact that the CA we created is self-signed and is not a public third party Certificate. Anyway..) Remember when the CRT and KEY are on the Client’s device, make sure the KEY is read-only by a root user.

  11. Identify Server side files

    Make note on our OpenVPN server the location of the following; ca.crt, dh2048.pem, OpenVPN-Server.crt, and OpenVPN-Server.key. We will need their full path for the next step

  12. Copy a sample server configuration file:

  13. Edit the server.conf file and change/add the following:

  14. Restart the OpenVPN service on the server.

  15. Client Configuration

    On your client, assuming Ubuntu OS is running on your client. Install the necessary packages for the OpenVPN Client

    After an OpenVPN option should be available in Network Manager, remember where your Client’s certificate and key are stored, then go to Edit Connections and the VPN Tab.
    certs on client

    Click Add, OpenVPN.
    Network Manager

    Now fill in the information necessary, Connection name, Gateway (which is your OpenVPN Server IP or DNS), User Certificate is your client CRT, CA Certificate is the ca.crt, and Private Key si the KEY file. See picture for example.
    Network Manager New

    The new connection should now appear in your Network Manager list of connections.

  16. Congratulations! You just set up a Client VPN Server and got a Client connecting over a secure SSL tunnel. Woot!

Sources:

Leave a Reply