0

I would like to have a simple CLI alias to connect my 5 clients (on my machine) to 5 OpenVPN servers, each of which uses the same password for verification.

Is this possible using a bash script? The password prompt comes milliseconds after the command to connect which is sudo openvpn --config client1.ovpn.

jsstuball
  • 4,104
  • 7
  • 33
  • 63
  • duplicate of https://askubuntu.com/questions/781345/vpn-one-liner-login-script https://unix.stackexchange.com/questions/386305/automatically-adding-user-and-password-to-openvpn-script https://stackoverflow.com/questions/26342569/bash-script-for-automated-openvpn-logon – jhnc Feb 09 '19 at 03:55
  • 1
    Not really a duplicate, although some of the ideas in the linked posts will be useful. All those links require password stored in plain text which is a security vulnerability. I want to be prompted once for a password common to 5 client connections. – jsstuball Feb 09 '19 at 05:08
  • 1
    I was considering passing password to a script as equivalent to storing in a file but I guess it's not exactly the same. Does openvpn allow credentials file to be a fifo? Have you considered expect? – jhnc Feb 09 '19 at 17:12
  • 1
    Expect was the solution I came across. – jsstuball Feb 09 '19 at 20:38
  • For clarity, what does "5 clients" mean in this context? Are you running 5 openvpn commands on a single machine, or connecting out to 5 other machines? – jhnc Feb 09 '19 at 21:45
  • Edited for clarity, fwiw I've made a simple expect script. Ty – jsstuball Feb 10 '19 at 04:49

2 Answers2

0

Expanding my comment, a fifo can be used like this:

#!/bin/bash

getpw(){
    read -r -p"username: " u
    read -r -p"password: " p
}

# ...

for client in {1..5}; do
    openvpn \
        --config "client${client}.ovpn" \
        --auth-user-pass <( printf "%s\n%s\n" "$u" "$p" )
done

# ...
jhnc
  • 11,310
  • 1
  • 9
  • 26
0

this is working for me.

#!/usr/bin/expect -f

# automatic openvpn login
spawn sudo openvpn File.ovpn

# script will enter username/password automatic. 
expect "Enter Auth Username:" 
send "USERNAME\n" 

expect "Enter Auth Password:" 
send "PASSWORD\n"

interact

end script

i am just a newbie, youll need to write yourself :)

Naive
  • 11
  • 2
  • 2
    Hey @Naive. Take a look into https://stackoverflow.com/help/formatting since a little bit of fomratting could really improve your answer ;) – acran Jul 26 '20 at 12:39