systemd for persistent SOCKS proxy

systemd for persistent SOCKS proxy

I'd like one browser to connect through a VPN but my main internet connection (and other browsers) to go through my ISP.

I already have a VPN running on a VM on Proxmox and figured I could use it as a proxy.

But if the SSH connection dies the proxy would disconnect so I need a way of keeping the SSH connection from dying!  

Step 1: create /etc/systemd/system/anon-socks.service

Description=SSH socks proxy

ExecStart=/usr/bin/ssh -N -D 9876 -q -i /home/MYUSER/.ssh/vm_pvt_key MYEXTERNALUSER@
ExecStop=kill $(pgrep -f 'ssh -N -D 9876 -q')


Make sure to update MYUSER to your username on the local machine, update -i /home/MYUSER/.ssh/vm_pvt_key MYEXTERNALUSER@ to the appropriate connection.

Restart=always is what restarts the service should it be interrupted for any reason (loss of connection, you suspend and resume your computer, etc.). This is what makes the proxy "undying!"

Step 2: reload

sudo systemctl daemon-reload
Reload the unit files

Step 3: enable it

sudo systemctl enable --now anon-socks.service
Enable it, starting it now

Step 4: connect to proxy

about:preferences#general > Network Settings > Settings > Manual proxy configuration

Step 5: well, you're proxied now

(assuming the VPN is running on the server - you should confirm you're IP has changed)