Showing posts with label VPN. Show all posts
Showing posts with label VPN. Show all posts

Saturday, April 30, 2016

"Invalid VPN secret" and only "add PPTP" in Network-manager

I will give the solution here to 2 annoying problems that I have encountered in Ubuntu 16.04 with VPN settings. 

Problem

The VPN connection to ... has failed because of invalid VPN secrets.

Network manager has no option to add openVPN, only point to point tunneling protocol connections.

Solution

These two issues are related, or I strongly assume, and the solution is to install some packages,
sudo apt-get install network-manager-openvpn network-manager-openvpn-gnome network-manager-pptp network-manager-vpnc

OpenVPN appears in network manager after installing selected packages
After installing the above packages, OpenVPN is back in the network manager.
To aply changes you may have to restart the network manager with
sudo service network-manager restart 
or simply reboot your computer.

Thanks to askubuntu.com. You can also set up easily a VPN autoconnect at boot after this.

Saturday, November 1, 2014

VPN Autoconnect at Startup in Ubuntu

I am using Ubuntu 12.04 with XFCE4 and the VPN Autoconnect option in the network configuration doesn't do any good. As far as I know this is a bug which causes the VPN autoconnect to malfunction if a new network is joined, be that ethernet or WiFi. This is kind of a big problem as one needs to connect to the internet first before the VPN connection can be established.

VPN Configuration - (Autoconnect checkbox does not work)
The solution I found best working is to create a shell script that manually connects to a VPN with a delay of 15 seconds. This delay allows sufficient time for the operating system to establish an internet connection, after which connecting to the VPN should be smooth. If you do not add a delay, the VPN connection may start before you have an internet connection and hence fail.

Tip: You can play around with the delay time, likely on a faster computer an internet connection may as well be established in under 10 seconds. My system takes a bit longer to boot and I found 15 seconds to be acceptable and working just fine.


List Available VPN Connections & Get UUID

Type,
nmcli con

This will give you an output with all your network connections, including the saved VPN profiles.
Copy the UUID of the VPN connection you want to establish. (I will refer to this as <UUID> further on)

Create a Shell Script that Manually Connects

Create a shell script, lets say call it VPNAutoconnect.sh with the following in it

#!/bin/sh
#Script to automatically connect to VPN
sleep 15;nmcli con up uuid <UUID>
(<UUID> here is of course the UUID you copied in the previous step)
make the script executable by
sudo chmod +x VPNAutoconnect.sh

Adding Script to Startup in rc.local

Add script to /etc/rc.local to have it executed at system start. Your rc local file will look something like this,
nano /etc/rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Set screen backlight to 75%
xbacklight -set 75
#Connect to VPN after 15 seconds (allows connecting to the internet first)
sh /route/to/script/VPNAutoconnect.sh
exit 0
Save the file and you are done. The next time the computer starts up, after the delay of 15 seconds set in the script file a VPN connection will be initiated. 

Of course you can also directly add the command to rc.local, however if you have multiple VPNs and plan to change it in the future, a separate file might be better (little longer script) where you can set which VPN you want to connect to. Also, using a separate script can help you keeping your rc.local file more clean and organized.

Important: Place the VPNAutoconnect.sh script somewhere where you will not delete it accidentally or move it. If the file is moved then at the next startup rc.local won't be able to execute it (clearly). The problem arises when you trust the script and go ahead browse the web and find it out 30 minutes later that you are not using a VPN specifically because the file was moved and hence at boot no connection was made. Yeah. I personally like having a "Scripts" directory under my home that contains such small scripts.