Pooya Golchian

moon indicating dark mode
sun indicating light mode

Setup and configuration SSH tunnel and create the poor man's VPN on Linux, MacOs, Windows 10

May 31, 2020

When you have a server and you want to have a VPN on the server. You can use this method. The following concepts are required to install.

  1. SSH
  2. Software or CLI to tunnel all internet in your device

Configure The Poor Man’s VPN (Tunnel over SSH) on MacOS, Linux

  1. Install and configuration proxychains4 (Next generation) from github
  2. Befor this configuration, You must be install gcc and make
 ./configure --prefix=/usr --sysconfdir=/etc
  make
  [optional] sudo make install
  [optional] sudo make install-config (installs proxychains.conf)
  1. Configure proxychanins4 from /etc/proxychains.conf
  2. Comment Socks4 and add Socks5 like blow:
socks5 127.0.0.1 1080
  1. You must be ssh to server like below(for Linux and MasOS):
ssh -f -N -D 1080 admin@server1.example.com
  1. You can check the proxy like curl -I twitter.com
  2. I’m wrote bash file to connect and disconnect to ssh in the MacOS. Poor Man’s vpn bash script
#!/bin/sh
NET_SERVICE="Wi-Fi"
PORT=1080
SERVER=admin@server1.example.com
PID=`pgrep -f ${PORT}`
if [ "$EUID" -ne 0 ]
  then echo "Please run as root!"
  exit
fi
if pgrep -f ${PORT} >/dev/null
then
echo "WELCOME TO POOR MAN'S VPN"
echo "Ssh process in running with pid" $PID
kill -9 $PID
echo "Kill ssh process with PID" $PID
else
echo "Ssh process not found"
fi
ssh -D ${PORT} -f -C -q -N ${SERVER}
echo "Connect to server"
networksetup -setsocksfirewallproxy ${NET_SERVICE} 127.0.0.1 ${PORT}
networksetup -setsocksfirewallproxystate ${NET_SERVICE} on
PID=`pgrep -f ${PORT}`
echo "Ssh runs on PORT "${PORT}" and PID "${PID}". socks proxy set on Wi-Fi"
echo "For turn off socks5 proxy run command -> sudo kill -9 "${PID}"; networksetup -setsocksfirewallproxystate "${NET_SERVICE}" off"
echo "Change proxychain4 socks5 port sudo sed 's/foor/bar/g' /etc/proxychains.conf"

Configure The Poor Man’s VPN (Tunnel over SSH) on Windows 7,10

  1. Install Bitvise and Proxifier
  2. Follow image to install and configuration the SSH tunnel on the Windows

Bitvise

Bitvise

Bitvise

Bitvise

Proxyfier

Proxyfier

Proxyfier

Proxyfier

Proxyfier


Pooya Golchian personal blog.
I'm Frontend developer and DevOps engineer.