brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: scutil --nc starts and stops a Mac VPN connection from the terminal

Terminal
~/tips/tip-macos-scutil-nc-vpn

scutil --nc list

Connects, checks and disconnects a macOS VPN service from Terminal or a script.

A VPN that you set up in System Settings, Network usually gets switched on with a click. That click is hard to put in a script. scutil has a little-known set of VPN commands that do the same thing.

The option is --nc, and scutil --nc help prints the full list. Start by listing the connection services in your current network set, with their names and status:

scutil --nc list

Then use the name you see there, in quotes when it has spaces:

scutil --nc start "Office VPN"
scutil --nc status "Office VPN"
scutil --nc stop "Office VPN"

status tells you whether the service is connected and adds extended details. show prints the configuration and statistics the bytes and errors. An example where I’d use it: a script that starts the work VPN, mounts a share and stops the VPN again when the job is done.

The caveat is about passwords. start accepts --user, --password and --secret, but anything you type there ends up in your shell history and in the process list. I’d let the password come from the keychain, which is where macOS keeps it when you save it in the VPN settings, and leave those options out. Also, this only covers services that macOS itself knows as network connections. A tool like Tailscale has its own command line, and that is the one I’d use for it.

Further reading: scutil man page (ss64), scutil –nc source (Apple open source)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link