How to setup VPN with your Ubuntu

VPN

First, update your local package cache using apt  

sudo apt update
 
 
 

Next, install StrongSwan and the required plugins for authentication:  

sudo apt install strongswan libcharon-extra-plugins
 
 
 

To ensure the VPN only runs on demand, use systemctl to disable StrongSwan from running automatically:  

sudo systemctl disable --now strongswan-starter
 
 
 

Next configure the username and password that you will use to authenticate to the VPN server. Edit /etc/ipsec.secrets using nano or your preferred editor:  

sudo nano /etc/ipsec.secrets
 
 

Add the following line, editing the highlighted username and password values to match the ones that you configured on the server:

/etc/ipsec.secrets
your_username : EAP "your_password"
 
Change your_username with your VPN service username, and your_password with your VPN service password. Your password has to be wrapped inside double-quotes. Notice the spaces after your_username, after “:” and after EAP.
 

Finally, edit the /etc/ipsec.conf file to configure your client to match the server's configuration:

/etc/ipsec.conf
config setup

conn ikev2-rw
    right=server_domain
    rightid=server_domain
    rightsubnet=0.0.0.0/0
    rightauth=pubkey
    leftsourceip=%config
    leftid=username
    leftauth=eap-mschapv2
    eap_identity=%identity
    auto=start
 
Change server_domain to the hostname of the server you are going to use, and username to your VPN username.
 
 

To connect to the VPN, type: 

sudo systemctl start strongswan-starter
 
 

To disconnect again, type: 

sudo systemctl stop strongswan-starter