Is this possible? I want to have one Shortcut which works like a On/Off button for a VPN (similar to a wireless on/off Button on many laptops). To achieve this, I would probably need a script involving the network manager?

Reason: I have to connect and disconnect my VPN a lot. Every of these connects or disconnects takes three clicks, which adds up, plus my mouse is very insensitive (even in the most sensitive setting)

I have LM 18.1 Mate, with 4.8 Kernel.

2 Answers 2


I just found the solution, very straight forward.

Simply creating two shortcuts, with the commands below:

for VPN ON: nmcli con up servername

for VPN OFF: nmcli con down servername

enter image description here

  • 6
    Thanks for the tip. I turned my single shortcut into a toggle with a conditional command: bash -c 'if [[ -n $(nmcli con show connection-name | grep "VPN connected") ]]; then nmcli con down connection-name; else nmcli con up connection-name; fi'. Commented May 31, 2017 at 7:20

I took this a bit further and thought I'd share it here.

I created a .sh script and an associated .desktop file so I can easily invoke this from Gnome.

The shell script I've placed in ~/.local/bin/vpn-toggle.sh

#!/usr/bin/env sh


if [[ -n $(nmcli connection show $CONNECTION_NAME | grep "VPN connected") ]]; then
  nmcli connection down $CONNECTION_NAME;
  nmcli connection up $CONNECTION_NAME;

Remember to change the CONNECTION_NAME to the name of your connection.

The .desktop file I've placed in ~/.local/share/applications/vpn-toggle.desktop

[Desktop Entry]
Name=VPN Toggle

You need to fix the Exec path to match your system. I couldn't get it to work with ~ and didn't care to investigate further.

  • You could make it better by making CONNECTION_NAME="$1" and wrapping around $CONNECTION_NAME with double quotations. The first one makes the script generalized, so that a user can give the VPN name as the argument, and second one makes spaces inside VPN name acceptable. Commented Feb 5, 2022 at 12:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .