Sunday, July 28, 2019

Running openvpn without it hanging the terminal

Whilst messing around with HackTheBox, I attempted to connect to the VPN from an Ubuntu VM I have with Google.

The annoying part was that after it ran, it would hang at "Initialization Sequence Completed", and required a second terminal connection to continue. If I Control+C'd, it would kill the VPN connection.

After a bit of searching, I found that I could run it then background it by going

> sudo openvpn Reelix.ovpn &

In which case it would still hang at "Initialization Sequence Completed", but I could Control+C it without it killing it. Close... But the hanging annoyed me.

After a bit more searching, I found that OpenVPN had a --daemon parameter, but going

> sudo openvpn Reelix.ovpn --daemon

Threw up an error

> Options error: I'm trying to parse "Reelix.ovpn" as an --option parameter but I don't see a leading '--'
> Use --help for more information.

After much searching, I eventually discovered the trick!

> sudo openvpn --config Reelix.ovpn --daemon


To kill the connection, I could either go

> sudo pkill -f "openvpn --config Reelix.ovpn"


> ps aux | grep openvpn
> sudo kill -2 processIdHere