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

Success!



To kill the connection, I could either go

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

Or

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

3 comments :

  1. Check out tmux for sesison, window and pane management in linux. I like running the openvpn blocking process in a background window so that I can check on it if I want. Sometimes it disconnects. Good intro: https://www.youtube.com/watch?v=Lqehvpe_djs

    ReplyDelete
    Replies
    1. An alarmingly late reply, but since I connect to by Linux box through SSH, I don't have the luxury of a full GUI setup which is why something like this is so important :)

      Delete
    2. I also only use SSH, but background it with tmux like in that video. It's pretty cool. Tmux keeps the session alive so if your SSH connection drops the session stays alive.

      Delete