Skip to content

Instantly share code, notes, and snippets.

@zenglian
Last active November 25, 2025 12:33
Show Gist options
  • Select an option

  • Save zenglian/8c7ee110b83cb8ffa033ba35ec1b6e8f to your computer and use it in GitHub Desktop.

Select an option

Save zenglian/8c7ee110b83cb8ffa033ba35ec1b6e8f to your computer and use it in GitHub Desktop.
auto login with cisco anyconnect (password saved, silent mode)

Cisco AnyConnect: auto login in silent mode

This gist is for Linux. For windows is the same thing.

Connect

create a file .login_info as below:

connect your.server.url    
usernanme  
password
    (blank line)  

create a script as below

/opt/cisco/anyconnect/bin/vpn -s < .login_info   

Trouble shooting

The input (content of .login_info) may vary according to your settings. Try VPN shell to determine your inputs.

Run
/opt/cisco/anyconnect/bin/vpn -s

Now you are in command shell:
VPN>

Connect your server:
VPN> connect your.vpn.server

Input what asked, for me it's below:
Username: [xxxxx] xxxxx
Password: xxxxxx

Exit from VPN shell:
VPN> exit (or return)

Remember what you typed, and save them into the .login_info file.

Disconnect

With this approach, the icon will not show in the taskbar, you need run command line vpn disconnect to disconnect.
If you want to show the icon in the taskbar, add below line in the script:

/opt/cisco/anyconnect/bin/vpnui &
@vtestah
Copy link

vtestah commented Feb 14, 2023

In the end, I got what I wanted.
On Ubuntu my script is like this:

#!/usr/bin/expect
spawn sudo /opt/cisco/anyconnect/bin/vpnagentd
expect ": "
send "HERE_SUDO_PASSWORD\r"
expect "$ "
spawn /opt/cisco/anyconnect/bin/vpn -s HERE_HOST
expect "*]*"
send -- "HERE_LOGIN\r"
expect "Password: "
send -- "HERE_PASSWORD\r"
expect "Answer: "
interact ++ return

At startup:
/usr/bin/gnome-terminal -- /PATH_TO_SCRIPT.sh

So, when my computer turns on, a terminal will appear where I just have to enter my unique SMS code.

@felicson
Copy link

felicson commented Dec 27, 2023

@momift
Copy link

momift commented Feb 27, 2025

I think the program isn't entering my password. Even if I don't include username, it's still picking it up when I run the/opt/cisco/anyconnect/bin/vpn -s script. Anyone else have an issue with supplying the password? I am getting a login failed when running the script, however I can log in manually with the VPN CLI.

I have the same problem as you.
How did you solve it?
Thank you

@Blastocerus
Copy link

Blastocerus commented Feb 27, 2025 via email

@genija
Copy link

genija commented Nov 25, 2025

On Windows this works for me.
vpn_connect.bat
"C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe" -s < c:\tools\connect_data.txt

c:\tools\connect_data.txt

connect HOSTNAME
USERNAME
PASSWORD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment