Fastest way to setup the actual state of the art VPN for cheap
Tags: linux, vpn, wireguard
Published: 2020-04-03 17:12:17

In this tutorial, we are going to see how to install Wireguard on a VPS with a few command lines!

## Step 1️⃣

You have to create a VPS instance to setup your VPN. I can advise you
[Scaleway](https://www.scaleway.com/en/), [Vultr](https://www.vultr.com/) or [Linode](https://www.linode.com/) because their prices are cheap.
Don't forget to check what kind of IP they have : all these providers have multiple geographical zones available to create a VPS instance.

I advise you to use Debian or Ubuntu image because we are using [PiVPN](https://www.pivpn.io/) to install Wireguard and it's optimized for debian based distributions. 

Personally, I'm creating a DEV1-S VPS instance located in France, with a Debian Buster image with a volume of 20 GB. Add your ssh key at the end of the process.

![Scaleway configuration](https://dev-to-uploads.s3.amazonaws.com/i/2crxap5voo9wps9bfpxn.png)

➡️ Click on the green button to build your instance!


## Step 2️⃣

To connect to your VPS, use the following command line : `ssh root@YOUR_VPS_IP`

For me, it was `ssh root@51.15.244.227` and upgrade your packages : `sudo apt update -y && sudo apt upgrade -y` and reboot the server `sudo reboot`

To secure your VPS server, I advise you to create an user account, setup your SSH key and disable password authentication to the server. I found some useful resources on the internet about these steps : [Disable SSH passwords on linux](https://www.cyberciti.biz/faq/how-to-disable-ssh-password-login-on-linux/), [Create sudo user on Debian](https://phoenixnap.com/kb/create-a-sudo-user-on-debian), [Disable the root access](https://www.addictivetips.com/ubuntu-linux-tips/disable-the-root-account-linux/) and [Change default SSH port](https://www.cyberciti.biz/faq/howto-change-ssh-port-on-linux-or-unix-server/)

Now, it's the right time to install Wireguard and PiVPN! First of all, I've got some errors during the installation with iptables-persistent package : now I have to run `sudo apt install netfilter-persistent`.
Sometimes, it can happen that you have to reboot your server to activate the changes.
Then, go to your user folder, and the command line to download and launch PiVPN installer :

```bash
curl -L https://install.pivpn.io > pivpn.sh
sudo bash pivpn.sh
``` 
   
For the first answer, select your user and then Wireguard. 

![Wireguard setup](https://dev-to-uploads.s3.amazonaws.com/i/3lg9tuiofzav56pz389y.png)

For the DNS selection : Quad9 or Cloudfare depending on your needs. You can find some article about them over the internet. Personally, I'm using Cloudflare for his speed.
You can respond the default answer to all the following questions except if you want to have a specific configuration

➡️ Reboot your system and tada! 🎉

##Step 3️⃣

Now the final step is to create and configure the client : 

![Client configuration](https://dev-to-uploads.s3.amazonaws.com/i/6ymoazvrpy4hxitm67eh.png)

The config file is located in your home folder, you can copy the configuration (as you can see above) and paste it in the [client app of your OS](https://www.wireguard.com/install/)

And now it has to works correctly! 🍻

![Wireguard client for macOS](https://dev-to-uploads.s3.amazonaws.com/i/azmrvjevqtyroncu9lul.png)
<figcaption>Wireguard client for macOS</figcaption>