Running openvpn as a systemd service.

Written by mikefettis | Published 2019/01/12
Tech Story Tags: vpn | hacking | systemd-service | openvpn | how-to-run-openvpn

TLDRvia the TL;DR App

photo by: mike fettis

VPNs are all the rage. All the cool kids are using them. The coolest kids only use a terminal on their linux. How about running openvpn as a systemd service and have an interactive prompt to let you know that your vpn is running?

Enter systemd, and PS1.The trick is to run the openvpn command as a systemd service. Then set it to auto-restart 15 seconds after failure. If we add a line to the opvn config file, auth-user-pass /home/linuxuser/pass.txt and then have the openvpn username and password in said txt file openvpn will be able to automatically connect to the vpn host. Finally, the icing on the cake is to update my PS1 (terminal prompt) to change color if the vpn is connected. This can be accomplished two different ways. 1). If the traceroute resolves the first hop to a 10.* ip address then I know that my vpn is connected2). If the service is in an active state then I know its running.

The in depth process is below.

There you have it, the vpn service will start on boot and will remain running all the time. If there is an issue then it will autorestart after 15 seconds. Just as a safeguard to make sure that all is good because we always want to know if the vpn is running ;) our terminal prompt will change colors based on the situation. A further enhancement can be done if you don’t want the entire terminal to change color and just hav ea symbol. This can be done if you look at the git integration that was done by, magicmonty. Hope this was a quick and easy read, and good luck with all your VPN-ing!

magicmonty/bash-git-prompt_An informative and fancy bash prompt for Git users - magicmonty/bash-git-prompt_github.com

links!!

systemd.service_It is possible for systemd services to take a single argument via the "" syntax. Such services are called…_www.freedesktop.org

BASH Shell Change The Color of Shell Prompt on Linux or UNIX - nixCraft_How do I change the color of my shell prompt under Linux or Unix operating systems? You can change the color of your…_www.cyberciti.biz

My new favorite Bash prompt - BrettTerpstra.com_I do a lot in Terminal. Sometimes, it's easier. Sometimes it's faster. Sometimes I'd just rather type it out. Whatever…_brettterpstra.com


Written by mikefettis | hacker and janitor building platforms and systems that when they work no one knows they are there.
Published by HackerNoon on 2019/01/12