Return home Return home

Jan 12, 2025

Quick and Easy VPN Management with OS X CLI

Due to the appealing metal case of MacBooks, I continue to use OS X as my operating system. However, I often contemplate the freedom and customization offered by Fedora, Ubuntu, and similar systems. A major advantage of these systems is their open-source nature, which provides numerous benefits, including the availability of command-line interface (CLI) utilities.

Discovering utilities like iTerm with zsh was a turning point, allowing me to integrate some of that open-source world into OS X.

Occasionally, I require a VPN, and I’ve found that the quickest and easiest way to manage it is through CLI commands. I eventually discovered Printunl, a regular app that also offers CLI access.

However, Printunl has a peculiar bug not documented in their GitHub repository issues. I can’t use profile names to start and stop them, only IDs. It’s impractical to memorize ID hashes like vpn start 34jfdsjgttjk3g. It would be much more convenient to use names, such as vpn start auth.

Instead of waiting for a fix, I wrote a small bash script to quickly access profiles by name.

function vpn() {
PRINTUNL_PATH="/Applications/Pritunl.app/Contents/Resources/pritunl-client"
if [[ "$1" = "start" || "$1" = "stop" ]] && [ -n "$2" ]; then
profile_id=$(vpn list | grep "$2" | awk -F'|' '{print $2}' | xargs)
$PRINTUNL_PATH "$1" "$profile_id"
else
$PRINTUNL_PATH "$1" "$2"
fi
}

First, install Printunl if you haven’t already. Then, add the script to your .zshrc file, set up your VPN profile, and you’re all set.

OLDER >