On-demand SSH Socks Proxy

On-demand SSH Socks Proxy

SSH config #

In order to avoid having to type the details every time I added them to ~/.ssh/config:

awk '/Host socks-proxy/' RS= ~/.ssh/config
Host socks-proxy
Hostname <HOSTNAME>
BatchMode yes
RequestTTY no
Compression yes
DynamicForward localhost:1234

Systemd-User Service #

Systemd-User Service Unit Definition File:

$ cat ~/.config/systemd/user/SocksProxy.service
Description=SocksProxy Over Bridge Host

ExecStart=/usr/bin/ssh -Nk socks-proxy


Reload systemd daemon with the new service definitions, enabled the new service, started it, checked its status, and verified, that it is listening:

systemctl --user daemon-reload
systemctl --user list-unit-files | grep SocksP
SocksProxy.service disabled

systemctl --user enable SocksProxy.service
Created symlink from ~/.config/systemd/user/default.target.wants/SocksProxy.service to ~/.config/systemd/user/SocksProxy.service.

systemctl --user start SocksProxy.service
systemctl --user status SocksProxy.service
● SocksProxy.service - SocksProxy Over Bridge Host
Loaded: loaded (/home/alex/.config/systemd/user/SocksProxy.service; enabled)
Active: active (running) since Thu 2017-08-03 10:45:29 CEST; 2s ago
Main PID: 26490 (ssh)
CGroup: /user.slice/user-1000.slice/user@1000.service/SocksProxy.service
└─26490 /usr/bin/ssh -Nk socks-proxy
netstat -tnlp | grep 118
tcp 0 0* LISTEN
tcp6 0 0 ::1:9118 :::* LISTEN