1

I have open-connect VPN and would like to always have a connection, even before I login with my own account.

I have Ubuntu 16.04.2, network-manager-openconnect-gnome.

If I run the command line nmcli con up id <VPN connection name> it will work, however it asks for username in a pop-up window, even it remember my username in visible text; then it asks for password, even it remembers it too (with the bullets), so I cannot use the nmcli directly to accomplish what I want.

Of course I still don't know how to make it totally headless (I mean run this before I login to Ubuntu), but that's next question after I can create something to connect the openconnect VPN without asking me the username and password.

1 Answer 1

1

Alright, after try and error I don't find a direct solution, but there is a workaround to use expect to achieve this.

Basically I write an expect script to send the Username and Password to the nmcli. Specifically that is

  1. sudo apt-get install expect, this will install the expect package
  2. create a file, call it connectvpn.sh

    #!/usr/bin/expect -f
    
    spawn nmcli -a con up id <VPN ID>
    expect "Username:"
    send "<username>\r"
    expect "Password:"
    send "<password>\r"
    expect "$ "
    
  3. chmod a+x connectvpn.sh

  4. now run it and it will work

Of course disadvantage is the username ans password will be saved in plain text in the script, but this is the best solution I can find.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.