Skip to content

Instantly share code, notes, and snippets.

@lockness-Ko
Created January 1, 2022 23:56
Show Gist options
  • Save lockness-Ko/6ae573d507cb4787d7275ad85d577563 to your computer and use it in GitHub Desktop.
Save lockness-Ko/6ae573d507cb4787d7275ad85d577563 to your computer and use it in GitHub Desktop.
Create your own vpn (because you can't trust shady VPN providers)

How to create your own VPN service

(because you can't trust shady VPN providers)

Overview

  • Create a VPS (virtual private server)
  • Login to your VPS
  • Clone the wireguard-install github repo and Run the script
  • Copy the client configuration file to your computer
  • Use your VPN

> 1. Create a VPS

"A virtual private server (VPS) is a virtual machine sold as a service by an Internet hosting service" (Amazon)

There are many different options for setting up a VPS, however, I have chosen digital ocean as they are the cheapest provider and the only one that I could sign up to for some reason.

> 1a. Create a droplet

To create a droplet, first, sign-in and click the create button in the top right and select droplets: image

image

Now choose your favourite Debian based image, basic plan, Regular intel with SSD and the $5/month plan. You do not need to select a block storage

You can choose anyone you want, however the cheapest one will suffice as it only uses 250Mb ram and up to 3% of the CPU, so the only thing you would need to get more of is bandwidth if you need it but 1TB should suffice.

image

You can choose the closest location for the datacenter region, although bear in mind that the closest one may not be the fastest (internet routing is done based on cost, not distance) so most of your traffic will probably be routed through the US

The VPC Network can be the default one unless you need to setup one for your own other purposes

For me in Australia, singapore is the closest:

image

For additional options, select IPv6 and Monitoring

image

For authentication you will need to create an ssh private key pair (password auth is less secure but go ahead if you want that)

To do this select the SSH keys option and click New SSH Key:

image

You can follow the tutorial on the window that pops up but one thing I might add is to run

ssh-keygen -t rsa -b 4096

instead of just plain old ssh-keygen

I would also recommend setting a password for your private key.

Next, you can choose a hostname (anything you want) and keep the auto generated project selected. You do not need to enable backups.

image

Now just wait for it to be online and then go to the next step!

image

> 2. Login to your VPS

To login, on windows you can use PuTTy and on mac or linux you can type

ssh -i ~/.ssh/your_private_key root@[2400:6180:0:d0::f9d:7001]

or just

ssh root@[2400:6180:0:d0::f9d:7001]

If you setup password authentication instead of ssh keys.

If you want to avoid all the hastle, you can just click the console button in the top right:

image

> 3. Clone the wireguard-install repo

Now you should be in the command line for your VPS.

First, you will need to update it and install git:

apt update && apt install -y git nano

To clone the repo type this command:

git clone https://github.com/angristan/wireguard-install.git
cd wireguard-install

This will get all the files, copy them to your VPS and then change directory (cd) into the folder where they were copied to

image

Now you can run the installer with:

bash ./wireguard-install.sh

image

First it will prompt you for an IPv4 or IPv6 address, use the default IPv4 address for your VPS (in the middle at the top of the droplet dashboard):

image

Keep the public interface and wireguard interface name, wireguard ipv6 and ipv4, wireguard port as their defaults and set the DNS resolvers as cloudflares fast DNS servers

image

Then let it install!

image

Now choose a name for your client (anything you want)

image

Now you can copy the wireguard configuration to your computer with scp on mac or linux:

scp -i ~/.ssh/path_to_your_private_key root@[2400:6180:0:d0::f9d:7001]:/root/wg0-client-CLIENTNAME.conf .

Or with PuTTy on windows.

If you want to use it on your phone just download the wireguard app for your app store and scan the QR code then switch it on!

image

image

> 4. Use you VPN (on windows, linux or mac)

To use your VPN on windows you will need to install it from their website https://www.wireguard.com/

Once you have done that you can add your configuration file and click activate.

On linux:

Run sudo apt install wireguard && sudo cp path/to/config/file /etc/wireguard/wg0.conf && wg-quick up wg0

Done!

Now you have your very own fast VPN!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment