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.
- SSH
- Software or CLI to tunnel all internet in your device
Configure The Poor Man’s VPN (Tunnel over SSH) on MacOS, Linux
- Install and configuration proxychains4 (Next generation) from github
- 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)
- Configure proxychanins4 from
/etc/proxychains.conf
- Comment Socks4 and add Socks5 like blow:
socks5 127.0.0.1 1080
- You must be ssh to server like below(for Linux and MasOS):
ssh -f -N -D 1080 admin@server1.example.com
- You can check the proxy like
curl -I twitter.com
- 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"