How To Connect To VPN Server with Cisco AnyConnect from Linux Terminal

Windows Articles

How to create a new KVM virtual Machine on Debian 10?

In the previous post, we explained how to install KVM on Debian 10. Now it's time to create a KVM Virtual Machine.

How to repair a USB drive in Windows 10.

Hi! USB sticks are undoubtedly very functional elements for working in Windows 10. Indeed, their use ranges from file management to creating...

How to install double-tap on back gesture on your Android

Hi, how are you? The double-tap on back gesture is one of the new functions available on Android 11 and IOS 14....

How to install KVM on Debian 10?

Hello friends, in this post I will show you how to install KVM on Debian 10. KVM stands for...

How to open Windows 10 Mobility Center

Hello! There are many types of users of Windows 10. As it depends on the type of hardware used. That is, the...

Connect To VPN Server with Cisco AnyConnect from Linux Terminal

Proceed with the way that how to Connect to VPN Server with Cisco AnyConnect from Linux Terminal. It’s easy to connect from desktop but this article help those who want to use Command line Interface. We have already covered how to Connect VPN from desktop. Let’s start with these steps to continue

Connecting to VPN Server with Cisco AnyConnect from Linux Terminal

Run the given command to check the status of being installed Cisco AnyConnect from the previous guide.

$ ls /opt/cisco/anyconnect/bin/                         
total 3.7M
-rwxr-xr-x. 1 root root 14K Dec 29 03:26 acinstallhelper
-rwxr-xr-x. 1 root root 783K Dec 29 03:26 acwebhelper
-rwxr-xr-x. 1 root root 688 Dec 29 03:26 anyconnect_uninstall.sh
-rwxr-xr-x. 1 root root 315 Dec 29 03:26 load_tun.sh
-rwxr-xr-x. 1 root root 506K Dec 29 03:26 manifesttool
drwxr-xr-x. 2 root root 4.0K Dec 29 03:26 plugins
-rwxr-xr-x. 1 root root 76K Dec 29 03:26 vpn
-rwxr-xr-x. 1 root root 999K Dec 29 03:26 vpnagentd
-rwxr-xr-x. 1 root root 418K Dec 29 03:26 vpndownloader
-rwxr-xr-x. 1 root root 398K Dec 29 03:26 vpndownloader-cli
-rwxr-xr-x. 1 root root 487K Dec 29 03:26 vpnui
-rwxr-xr-x. 1 root root 9.2K Dec 29 03:26 vpn_uninstall.sh

Check out the vpn connection script command options:

$ /opt/cisco/anyconnect/bin/vpn --help
Usage: vpn [options] | [cmd] [host] options: -h Print this usage statement. -v Print version. -s Read commands from response file to work non-interactively. Example: vpn -s < response.txt commands: [connect|disconnect|hosts|state|stats]

See the connection example

$ /opt/cisco/anyconnect/bin/vpn -s connect 192.168.10.10

Allow untrusted connections upon Prompt & provide user details to login to VPN

Copyright (c) 2004 - 2019 Cisco Systems, Inc.  All Rights Reserved.
state: Disconnected
state: Disconnected
notice: Ready to connect.
registered with local VPN subsystem.
contacting host (192.168.10.10) for login information…
notice: Contacting 192.168.10.10.
AnyConnect cannot verify server: 192.168.10.10
- Certificate does not match the server name.
Connecting to this server may result in a severe security compromise!
Most users do not connect to untrusted servers unless the reason for the error condition is known.
Connect Anyway? [y/n]: y
Please enter your username and password.
Username: sabi0329
Password: xxxxxxxx
Second Password:

The connection should be initiated if correct credentials were provided.

        state: Connecting
notice: Establishing VPN session…
Connection will be established if you have provided the correct credentials.
state: Connecting
notice: Establishing VPN session…
The AnyConnect Downloader is analyzing this computer. Please wait…
Initializing the AnyConnect Downloader…
The AnyConnect Downloader is performing update checks…
notice: The AnyConnect Downloader is performing update checks…
notice: Checking for profile updates…
notice: Checking for product updates…
The AnyConnect Downloader updates have been completed.
Please wait while the VPN connection is established…
notice: Checking for customization updates…
notice: Performing any required updates…
notice: The AnyConnect Downloader updates have been completed.
state: Connecting
notice: Establishing VPN session…
notice: Establishing VPN - Initiating connection…
notice: Establishing VPN - Examining system…
notice: Establishing VPN - Activating VPN adapter…
notice: Establishing VPN - Configuring system…
notice: Establishing VPN…
state: Connected

See the status of VPN by

$ /opt/cisco/anyconnect/bin/vpn state 
Cisco AnyConnect Secure Mobility Client (version 4.7.01076) .
Copyright (c) 2004 - 2019 Cisco Systems, Inc. All Rights Reserved.
state: Connected
state: Connected
state: Connected
registered with local VPN subsystem.
VPN>

Pull connection stats by typing

$ /opt/cisco/anyconnect/bin/vpn stats 

How To Disconnect VPN

Use the following command to disconnect VPN.

$ /opt/cisco/anyconnect/bin/vpn -s disconnect 192.168.10.11

Note: Replaces IP with your VPN Server IP address.

Automate VPN Connection from CLI

To create an automatic connection, make a script first creating user details.

$ vim ~/.vpn_creds
username
Password
y

Set up username, password in the file. Then create a script file like below:

$ vim vpn_connect.sh
!/bin/bash


VPN_SERVER="192.168.10.10"


echo "Connecting to VPN.."
/opt/cisco/anyconnect/bin/vpn -s < ~/.vpn_creds connect ${VPN_SERVER}

Now, make the script executable to run because without executable it wouldn’t run.

$ chmod +x vpn_connect.sh

Now, run the script to Connect to your VPN

$ ./vpn_connect.sh
Connecting to VPN..
Cisco AnyConnect Secure Mobility Client (version 4.7.01076) .
Copyright (c) 2004 - 2019 Cisco Systems, Inc. All Rights Reserved.
state: Disconnected
state: Disconnected
notice: Ready to connect.
registered with local VPN subsystem.
contacting host (192.168.10.10) for login information…
notice: Contacting 192.168.10.10.
Please enter your username and password.
Username: [jkmutai] jmutai
Password:
state: Connecting
notice: Establishing VPN session…
The AnyConnect Downloader is analyzing this computer. Please wait…
Initializing the AnyConnect Downloader…
The AnyConnect Downloader is performing update checks…
notice: The AnyConnect Downloader is performing update checks…
notice: Checking for profile updates…
notice: Checking for product updates…
notice: Checking for customization updates…
The AnyConnect Downloader updates have been completed.
notice: Performing any required updates…
Please wait while the VPN connection is established…
notice: The AnyConnect Downloader updates have been completed.
state: Connecting
notice: Establishing VPN session…
notice: Establishing VPN - Initiating connection…
notice: Establishing VPN - Examining system…
notice: Establishing VPN - Activating VPN adapter…
notice: Establishing VPN - Configuring system…
notice: Establishing VPN…
state: Connected

Enjoy secure connection.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to create a new KVM virtual Machine on Debian 10?

In the previous post, we explained how to install KVM on Debian 10. Now it's time to create a KVM Virtual Machine.

How to repair a USB drive in Windows 10.

Hi! USB sticks are undoubtedly very functional elements for working in Windows 10. Indeed, their use ranges from file management to creating...

How to install double-tap on back gesture on your Android

Hi, how are you? The double-tap on back gesture is one of the new functions available on Android 11 and IOS 14....

How to install KVM on Debian 10?

Hello friends, in this post I will show you how to install KVM on Debian 10. KVM stands for...

How to open Windows 10 Mobility Center

Hello! There are many types of users of Windows 10. As it depends on the type of hardware used. That is, the...