Open Vpn
Tags: cloud, devops, vpn, openvpn
Published: 2022-04-08 15:54:57

**How to connect a private server(i.e. the server without a public IP address)?**
Well there is a solution for the above concern, which leads us to learn a new concept named OpenVpn.

So, what is OpenVpn? 
Well OpenVpn is a type of computer network that provides users with remote access to resources on the internet.


So how can we use it to connect a server?
Well the solution to the above query is given below.

STEP 1. Launch an instance without public IP.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jy2bs6csj4xnrfqy9hbl.jpg)

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

**So, to connect the server we have to setup a VPN connectivity.
**
STEP 2.  Go to **launch instances** then in the search bar search for openvpn -> click on 44 results.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iuprcoedu7anukfkmrm6.jpg)

Then select the 1st openvpn.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9wodzdzhu4w1d31zn9g.jpg)
STEP 3. Then launch another instance with public IP enabled -> create new key pair -> launch instances.
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxd6ilf6trdvl0uqbsp4.jpg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l46io5fzgvrzo3ap49fq.jpg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yy5s59wex3dn2sxfy87m.jpg)

**Now, we can see that both the instances which we have launched have same VPC ID.**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hh8ulwfa11tj4rxmdfcr.jpg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/quwjd6ejhrvmvevoh3sk.jpg)

STEP 3. Now we need to connect the second server i.e. with public IP to Xshell -> Then type yes and then enter multiple times.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/esfruzlhmlzqo8t9j4bl.jpg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5463wrylspezys6gs2j.jpg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eairznxwhsu13dhuwvtr.jpg)
Then openvpn will initialize
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x2gv71uv3p4na7amv5c5.png)
Then after some time again paste the same command (SSH client) and  of root write **openvpnas** -> then again connect with the key pair.

Now already a openvpn (user) is created so now we have to change password.
So, type sudo passwd -> enter
Give password
  
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mlrpschrcjip3qb2dnhw.png)

Then scroll up and copy link of Admin and Client and paste it in notepad.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yj99bicyh2c87kj6t3u8.png)
Now close Xshell.

Now, copy the admin's url and paste it in browser -> login to openvpn -> Agree
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmgcv17fob8a05lkq6xu.jpg)
  
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gc5owy5q4aq9afed1n82.jpg)

Now again go to instances.
Then connect the instance (without public IP) through Xshell
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9kvt83isixfrllnfj57.jpg)
 
But we will notice that it wont get connected.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1bsgxnbmx56rhmpg6x2.png)

STEP 4. Now open OpenVpn  -> connect -> next (multiple times) -> agree ok -> Give url i.e. copy the IP of client link and paste -> next -> accept -> username : openvpn ->Password: give the password which u have set earlier in Xshell -> Accept -> Connect -> Password -> OK

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jydeto7tgups0f8kudu4.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ejikilx1jqgo44dasbpe.png)
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kvrodgjaj5dbov9tcgdz.png)
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o4lc8xjfefochf2czlda.png)
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mr409fvnlhkd8ji1irok.png)
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/81d45nzzct4vcplwnrmi.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvjpdyq3p4kdd7p68nz0.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eujy7wo7kkpjkxywh6yj.png)
   ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrittu641mc08p0wtuzt.png)

Then go to Xshell and try to connect the instance (without public key) again. Now, u will be able to connect/access the instance. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0o1hs44t7kcste5t5o4r.png)


So, this is the way by which we can connect servers without public IP address through openvpn.