I have tried VPNs in the past but for whatever reason they always disconnect after a certain amount of time despite selecting automatically connect. I found a post on how to keep a VPN alive by using network manger command line and cron to schedule the command.
Make sure a VPN connection is configured (beyond the scope of this post) using the Ubuntu network manager and ensure it works. It’s best to give the VPN a name without spaces.
The first step is to test the setup of the VPN is correct as well as checking the command works. Make sure the VPN is disconnected.
nmcli con up id [myVpn]
where [myVpn] should be replaced with the name of the VPN connection. If the VPN connects after running the command then the test was sucessful.
Login as the user who requires the VPN connection.
Append the following entry replacing [myVpn] with the name of the VPN connection:
* * * * * /usr/bin/nmcli con up id [myVpn]
The above will run every minute but it can be changed to any frequency (see man crontab)
I’ve been running this for few days and the VPN connection seems stable enough to leave it running.