How to Setup an AWS Client VPN Using OpenVPN on EC2

In this tutorial, we will explore how to set up a basic client VPN on Amazon Web Services (AWS) EC2 using OpenVPN Access Server. The scenario involves establishing a VPN connection between your on-premises client and the private network within AWS. By the end of this step-by-step guide, you’ll be able to access your AWS cloud resources, such as other EC2 instances, securely and efficiently.

Before you start, you need to create a Virtual Private Cloud (VPC) to launch the OpenVPN on that VPC. We already have a tutorial on how to create your own VPC on AWS here.

Step 1: Sign in to AWS Console

Open your web browser and go to the AWS Management Console (console.aws.amazon.com).

Sign in with your AWS account credentials.

Screenshot showing login page of aws

Step 2: Navigate to EC2 Dashboard

Once you’re logged in. In the search bar search  “EC2” and click on the EC2.

Screenshot showing selecting the AWS EC2 Service

Step 3: Creating an EC2 instance 

First select the region that you want to create the VPN on. 

Then click on the “Launch Instance” button as shown in the picture below.

Screenshot showing selecting the region and launching the aws instance

Step 4: Setting up the EC2 details

Give the name of the ec2 instance.

Click on browse more AMIs.

Screenshot showing browsing the OpenVPN AMI

Search “openvpn” on the search bar.

Click on the “Select” next to OpenVPN Access Server and then the “Continue” button.

Screenshot showing searching the AMI

Now you can see the details required to launch the OpenVPN are filled automatically.

Screenshot showing details of the AWS instances

By default there will be a “t2.small” instance selected. Let’s select the Free tier eligible “t2.micro” instance. 

Screenshot showing selecting the t2.micro instance

On the Key pair(login) section. Click on “Create new key pair.” We need to ssh into that instance for the setup of OpenVPN and for that we need a key pair file. (store this file securely, because it contains the information about the instances)

Screenshot showing creating a key pair for instance

Provide a name for your key pair and select RSA and .pem as key pair format and click on “Create key pair.” It will automatically download the .pem file on your device. (you can also use the .ppk file format if you are using a third-party ssh client like PuTTY). 

Screenshot showing providing the key pair details

Leave all the things as default and click on “Launch Instance.” We are leaving all the details as it is which was suggested by the AMI that we choose from AWS Marketplace. 

(If you want to use your own VPC, Subnet, and Security Group you can select those from the Network Setting tab by clicking the “Edit” button)

Screenshot showing launching the instance

Wait for the instance to be launched and running with status checked as 2/2 checks passed.

Screenshot showing checking the instance state

Step 5: Connecting to the instance 

Select the instance that we have created and click on “Connect.”

Screenshot showing connecting the instance

Select the “SSH client” and click on the copy icon and the command given in the Example tab will be copied to your clipboard.

Screenshot showing connecting the instance through ssh

Open your terminal.

Navigate to the folder from your terminal in which your key pair that we have created is downloaded. (In most cases it will be in the Downloads folder). The command will be: 

cd downloads
ssh -i "vpnServerRKey.pem" root@ec2-54-179-71-172.ap-southeast-1.compute.amazonaws.com

Paste the above copied command in your terminal and click Enter.

Screenshot showing connecting the instance from our local computer

Type “yes” to continue

yes

It will show the message to login as a openvpnas user rather than root. So lets login as a openvpnas user. 

Screenshot showing login into the server

 Just replace the root@ to openvpnas@ and paste that same cmd to your terminal.

ssh -i "vpnServerRKey.pem" openvpnas@ec2-54-179-71-172.ap-southeast-1.compute.amazonaws.com
Screenshot showing login to the server through openvpnas username

Congrats now we are inside the ec2 instance.

Step 6: Setting up OpenVPN 

Type “yes” and press “Enter” as we will set everything as default to all the configurations. 

Screenshot showing setting up the default configuration

Wait for some time and it will be ready in a few seconds.

Screenshot showing details of the openvpn server

We can see the Admin UI url and Client UI url with username and password for admin. Copy the login details username and password. We will need it later in many steps and also while connecting. 

Step 7: Accessing OpenVPN Web UI

Copy the Admin UI and enter the username and password that have been created above.

Screenshot showing accessing the OpenVPN admin UI

Now you can see the OpenVPN web dashboard.

Screenshot showing OpenVPN admin dashboard

Step 8: Connecting to the VPN 

First we will make sure that all our traffic is safe and secure and will go through this traffic. Then we will create a user to connect to this VPN. 

Click on “Configuration” and then “VPN Settings.”

Screenshot showing OpenVPN configuration setting

Scroll down to the Routing section and then in the option “Should client Internet traffic be routed through the VPN?” we will select “Yes.”

Screenshot showing setting up internet traffic routed through VPN

Scroll down to last and click on “Save Settings.”

Now click on “Update Running Server.”

Screenshot showing updating the running server

After that, copy the url without /admin and fill up the same details that have been created above.

Then click on “Sign In.”

Screenshot showing accessing the user web UI portal

Select your OS and it will automatically download the application files.

Screenshot showing selecting the OS and downloading the file

Install the application and open it.

Screenshot showing opening the OpenVPN application

Click on the On button on the left side. It will ask you for your password. Type your password that has been used before. And click on OK.

Screenshot showing adding the details of the OpenVPN user

Congrats, your VPN has been successfully configured.

Screenshot showing VPN connection established successfully

Now you can use your own VPN to connect to your instances and database on the same VPC inside your AWS region.

Security and best practices considerations

The setup in this guide is a very basic proof-of-concept type configuration. Before using this VPN setup in production I recommend implementing strict access controls and security groups to limit access to the OpenVPN Access Server instances only to necessary IP addresses or ranges.

Also, since in this configuration the VPN appliance would be a single point of failure, you may want consider purchasing a second instance configuring both in high-availability (HA) mode behind an Elastic IP Address. The Elastic IP address serves as the public IP access point to the Admin Web UI as well as the tunnel-establishment endpoint for VPN clients. At a minimum, it’s a best practice to associate an Elastic IP Address to your EC2 instance with OpenVPN Access Server so you can easily remap the same address to another instance in case the current instance fails.

Then there are the more common, cautionary suggestions such as ensuring you use strong password policies for VPN users, regularly review user access to remove inactive or unnecessary accounts, consider enabling multi-factor authentication (MFA) to add an extra layer of security, and setting up a logging solution to capture connection and activity logs such as AWS CloudWatch.

Recommended Tool: ManageEngine OpManager

  • Multi-vendor Network Monitoring
  • Simple Installation & Setup
  • Intuitive UI
  • Complete Visibility
  • Intelligent Detections
  • Easy Resolutions

Leave a Reply

Your email address will not be published. Required fields are marked *