How to connect to a private instance using VPN.
Tags: aws, cloud, devops, beginners
Published: 2022-08-20 11:15:00

In a previous blog, I explained how to connect to an instance with private IP. This blog explains how to connect to the private instance using a VPN.

**step 1:**
First, create an instance that does not have a public IP.
**step 2:**
Go to Amazon AMI->Market Place search OpenVPN and click on select->continue.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8l8w3fih4v44bxvhevs4.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gv2mnqi9h9o3g2z72nj.png)

**step 3:**
After this configure the instance and make sure to give it a public IP.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9rqcxno9sipczq7i2bme.png)
**step 4:**
Then connect to the instance using the ssh client then click yes to agree on agreements and click enter to every option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m93ntcpjws64jj49xxyx.png)
**step 5:**
It won't connect because we have to change the name root to openvpnas. Copy the Admin UI and Client UI to the notepad. Then connect by giving username openvpnas. Because we are trying to connect to the vpn, not the root.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hhul4y2g9h7jcy8ah27a.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iywegi12u3m7f6ubvk9p.png)

**step 6:**
After it will get connect give the password to the vpn by providing the following commands.
`sudo passwd openvpn`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5wim5xiz1cmk9o15qt8.png)
**step 7:**
After that go to notepad where you pasted the Admin UI and client UI. Again copy the Admin UI then paste it on google search. Then it will ask you for the id and password. Provide the id as OpenVPN and give the password you have created and log into that VPN. There you can manage who can access the server and other permissions.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93has60pe1d1ug2ga1bh.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrtzyznifhs9bjxlaq60.png)

**Step 8:**
After that go to openvpn website and install OpenVPN in the client's system so they also can connect to the private server.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2adlth3wqxiekjtepzv.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmit6bx6lskf0bn7cpgl.png)
**Step 9:**
After the installation, copy the client UI, paste it into the URL, and give the password you created and on the VPN so that the client can access the private server.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/529saj9ikmbexhy4pb7a.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i85mw5ek2amcmv1ig779.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffff41ecb6yvx1z1sg8o.png)


That's it. After these steps, both you and your clients will be able to connect to the private server.

Hope you all find it informative!!