Skip to content

Tutorial + script to handle connections of AnyConnect VPN via command line

Notifications You must be signed in to change notification settings

simonschuhmacher/openconnect-vpn-zhaw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Convenience script to connect to AnyConnect VPN server at ZHAW via OpenConnect

This script allows to connect to a AnyConnect VPN server using SSO for authentication via command line. Tested on macOS, probably working as well for Linux with some minor modifications.

The following tools need to be installed to use the script.

Install OpenConnect

brew install openconnect

Install OpenConnect-SSO

Install pipx

Optional, but recommended, see https://github.com/pypa/pipx.

brew install pipx

OpenConnect-SSO

pipx install "openconnect-sso[full]"

once finished installation, run

pipx ensurepath

Connect manually to server

To save the password to keychain, run the openconnect-sso command once manually (yourname needs to be changed to your name / abbreviation):

sudo openconnect-sso --server "ras.zhaw.ch" --user="[email protected]"

Log in in the web view showing up. Password will then automatically be saved to keychain.

Modify script

Modify the script found in this repo called vpnzhaw with your information, namely your email address, by setting the correct value for the variable VPN_USER correctly (replace yourname):

Make the script executable:

chmod +x vpnzhaw

Place the modified script at usr/local/bin/

Allow to run the script without sudo (optional)

The script needs root permission to work properly. To allow executing it with sudo without entering a password, add the file /private/etc/sudoers.d/vpnzhaw, for example using nano:

sudo nano "/private/etc/sudoers.d/vpnzhaw"

and paste the following to the file

yourmacusername ALL=(ALL) NOPASSWD: /usr/local/bin/vpnzhaw

replace yourmacusername with your actual username. To get this, run whoami in terminal.

(If using nano, save with CTRL+o and exit with CTRL+x)

Using the script

Installation should now be finished. Use the script with the following commands:

  • vpnzhaw start to start a new connection to the VPN server. If not yet connected, just executing vpnzhaw will start a new connection as well.
  • vpnzhaw status to show whether OpenConnect is currently running. If OpenConnect is currently running, just executing vpnzhaw will show the status as well.
  • vpnzhaw stop to close the existing connection.

Enjoy 😚

About

Tutorial + script to handle connections of AnyConnect VPN via command line

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages