2

I got this function in a bash script:

function start_vpn() {
sudo ip netns exec frootvpn openvpn --config /etc/openvpn/frootvpn.conf &

while ! sudo ip netns exec frootvpn ip a show dev tun0 up; do
    sleep .5
done
}

It fails because it doesn't stop to let me enter the private key password. When I enter sudo ip netns exec frootvpn openvpn --config /etc/openvpn/frootvpn.conf manually I got the private key prompt but in the script it doesn't wait for me to enter it :)

euri10
  • 2,446
  • 3
  • 24
  • 46
  • I semi solved it with http://stackoverflow.com/questions/11240184/pass-private-key-password-to-openvpn-command-directly-in-ubuntu-10-10 but it means hhaving a file with the pass in it which I dont like – euri10 Jul 13 '15 at 12:10

2 Answers2

2

If you mean the sudo password you can try

sudo sh -c 'ip netns exec frootvpn openvpn --config /etc/openvpn/frootvpn.conf &'

For the openvpn password you could try asking it to read it from a fifo. You would then echo your password into the fifo. I havent tried this.

mkfifo ~/myfifo
sudo sh -c 'ip ... openvpn --askpass ~/myfifo ... &'

Then interactively, if you dont want your password echoed:

$ stty -echo; cat >~/myfifo; stty echo
type your password
type control-D for eof
meuh
  • 11,500
  • 2
  • 29
  • 45
  • mmm it says me : Broadcast message from root@bigbenn (Mon 2015-07-13 14:08:19 CEST): Password entry required for 'Enter Private Key Password:' (PID 7373). Please enter password with the systemd-tty-ask-password-agent tool! – euri10 Jul 13 '15 at 12:09
  • Sorry, I thought the problem was sudo. I added a suggestion for openvpn. – meuh Jul 13 '15 at 12:32
0

Here is my solution to enter automatically both passwords on a Linux/Ubuntu-system. (The sudo-pw and the openvpn-pw.)

In the file /home/user_name/.bashrc I added the row:

alias run_openvpn='sudo date < /path/to/sudo_pw_file && sudo openvpn --config /path/to/key_file --askpass /path/to/private_key_file'

In the files sudo_pw_file and private_key_file the passwords are stored in plain text. So there is a security risk involved.

Then you can execute exec bash from the terminal.

From then onwards you may establish the vpn-connection from the terminal with run_openvpn.

The sudo date I used to enter the sudo-password in a preliminary step so that it is not asked for in the other command.

Btw: you may configure your vpn-connection as well with > settings > network but they interfere if I start to vpn-connections from there. So I start one from terminal and one from there.

Thomas R
  • 1,067
  • 11
  • 17