Setup a free VPN on AWS

Setup a free VPN on AWS

Like i told you on previous posts, i am preparing for the AWS Developer Associate Certification.

As i study for this certification, i am learning some stuff about the cloud and in this tutorial, i am showing you how to setup a free VPN on AWS.

What is a VPN ?

A virtual private network (VPN) gives online privacy and anonymity by creating a private network from a public internet connection.
To explain it in simple words, i am gonna use the definition that you can find here

In very simple terms, a VPN connects your PC, smartphone, or tablet to another computer (called a server) somewhere on the internet, and allows you to browse the internet using that computer’s internet connection. So if that server is in a different country, it will appear as if you are coming from that country, and you can potentially access things that you couldn’t normally.

It's exactly what we are gonna do.

How come is that free ??

Amazon Web Services has a free tier available for 12 months.
We are gonna use this free tiers to setup the VPN.
Of course, after 1 year, AWS is gonna charge you for it, but until that, you can play with it without spending any money !


The first thing you need is to create an AWS account.

Once you have that, you are going to open the Amazon Management Console and click on Services

We are going to use EC2 (Amazon Elastic Compute Cloud)


Once you are in the EC2 page, click on Launch Instance


On the left, click on AWS Marketplace and type OpenVPN.
We are going to choose a virtual machine where OpenVPN is pre-installed.
Click on select

Capture d’écran de 2020-10-12 17-58-36.png

On the next pop-up, you are going to see the following.
Don't worry, it's free for 2 clients !
Click on continue.


Then, choose the free tier eligible instance (not like i did on the capture haha).


Then, click on Launch

Capture d’écran de 2020-10-12 18-01-21.png

A pop-up is gonna ask you for a key pair.
Create a new one and download it !
Keep the file, you are going to need that later.
Click on Launch Instance


Wait a little bit for the instance to be ready for you :) !


Now, we are going to connect to the machine with the key pair that we created a few steps above. On the EC2 instances list, right click on yours and hit "Connect". Capture d’écran de 2020-10-12 18-04-21.png

On the next page, choose the third choice : SSH connect

Capture d’écran de 2020-10-12 18-05-08.png

Open a terminal, on your computer and copy paste the example on the screen

ssh -i "my_vpn.pem"

Be sure to be on the right folder where you downloaded your key. If not, modify the command like this

ssh -i "/path_where_my_doc_is/my_vpn.pem"

Capture d’écran de 2020-10-12 18-11-31.png

Hit enter !

Capture d’écran de 2020-10-12 18-15-11.png

If you are going too fast, (like me :p ), you are probably gonna see this error. You need to chmod the file ! They say it on the window where you choose SSH and copy the command, but i did not read the whole thing ...

Capture d’écran de 2020-10-12 18-16-46.png

After that, try again to connect, it's gonna work. At the end, a message will say that you need to connect with the openvpas user instead of the root user.
Type this instead and hit enter

ssh -i "my_vpn.pem"

Capture d’écran de 2020-10-12 18-19-43.png

Last thing, we are going to set up the password for the openvpn user

openvpnas@ip-XXX-XX-XX-XXX:~$ sudo passwd openvpn
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

Now on your EC2 instance details, get the Public IPv4 DNS.
Go on your browser and type this to access to the admin dashboard.
(Don't forget the https in front of it )


Capture d’écran de 2020-10-12 18-34-26.png

Capture d’écran de 2020-10-12 18-35-09.png

The user is openvpn.
The password is the one you just created.

Capture d’écran de 2020-10-12 18-35-17.png

Now, one last thing, go one the Configuration > VPN Settings on the left, scroll down until you can set the following option : route all the traffic through the VPN !

Capture d’écran de 2020-10-13 17-45-24.png

Save and Update Running Server.


You did it !

What's next ?

We installed and deployed a VPN on the cloud!
The next step is, how to connect to this VPN, as a user !
We are going to see that on the following article :)


This is just an example of what you can do with AWS EC2, you can install pre-configured instances with almost everything, like a Windows Server, or a specific version of Linux , you just name it, i'm sure it's available on the AWS MarketPlace.

I don't recommend using this VPN for your day to day use, because i am not sure about the limitations regarding the performances (it's the free tier, but i am sure it's somehow limitated somewhere), but you can just play with it and discover AWS services through this tutorial.

Did you find this article valuable?

Support Sonia Manoubi by becoming a sponsor. Any amount is appreciated!