SSH SOCKS proxy via MacOS X launchctl

I use an SOCKS proxy to connect to some services in different networks. For that reason I use a simple SSH SOCKS proxy solution which makes it really easy:

ssh -f -N -D7070

But running this command every time when I switch my location or the laptop hibernated is not really convenient. MacOS X provides launchctl as a service manager, so why not using it?

Agents running for the current user are stored in ~/Library/LaunchAgents/ as an XML based plist file. I named my file like the host I'm using to connect to, so it's com.example.gateway.socks-tunnel.plist.

My file looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
            <string>-o ControlMaster=no</string>

If you're using ControlMaster ssh settings you should disable it for the tunnel setup via -o ControlMaster=no. For the first time it requires to load the plist file:

launchctl load ~/Library/LaunchAgents/com.example.gateway.socks-tunnel.plist


September 16, 2015, 3:18 pm


, , , , ,




Send your comment by mail.