Last active
August 22, 2018 04:32
-
-
Save mplinuxgeek/746e77369c93b0fe9e9d12719b55538f to your computer and use it in GitHub Desktop.
SSH SOCKS tunnel helper script, opens tunnel, checks that the port is open then launches Firefox, the ssh session closes after 10 seconds which is enough time for Firefox to start but the tunnel will remain open till Firefox is closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# SSH SOCKS tunnel helper script, opens tunnel, checks | |
# that the port is open then launches Firefox, the ssh | |
# session closes after 10 seconds which is enough time | |
# for Firefox to start but the tunnel will remain open | |
# till Firefox is closed. | |
# | |
# Changes: MP - 22/08/2018 - Initial version, tested on Ubuntu 18.04 and Windows under Cygwin | |
# | |
# Todo: Add proper detection of Cygwin environment | |
# Username of account on remote ssh server | |
USERNAME=username | |
# Hostname or IP address of remote ssh server | |
HOST=remotehost.not.a.real.domain | |
# Port of the remote ssh server | |
SSH_PORT=remote ssh port eg 22 | |
# Local SOCKS port to create | |
SOCKS_PORT=8123 | |
echo -ne "Bringing up SOCKS tunnel on port ${SOCKS_PORT}... " | |
if ssh -D ${SOCKS_PORT} -f -C ${USERNAME}@${HOST} -p ${SSH_PORT} sleep 10 > /tmp/ssh_error 2>&1; then | |
echo "done" | |
else | |
echo "failed" | |
cat /tmp/ssh_error | |
exit 1 | |
fi | |
echo -ne "Checking status of port ${SOCKS_PORT}... " | |
if timeout 1 bash -c "</dev/tcp/localhost/${SOCKS_PORT}" -eq 0; then | |
echo "open" | |
else | |
echo "closed" | |
exit 1 | |
fi | |
echo -e "Starting Firefox... " | |
# Check if Firefox is a valid command and execute it, else it could be cygwin so we'll try the Windows version of Firefox | |
if command -v firefox &> /dev/null; then | |
firefox > /dev/null 2>&1 & | |
else | |
FIREFOX="/cygdrive/c/Program Files/Mozilla Firefox/firefox.exe" | |
if [ -f "${FIREFOX}" ]; then | |
"${FIREFOX}" > /dev/null 2>&1 & | |
fi | |
fi | |
echo -e "\nNetwork Proxy in the web browser needs to be configured" | |
echo "Firefox:" | |
echo " • Menu (3 bars in the top right corner), click Options or Preferences" | |
echo " • Under \"Network Proxy\" click Settings" | |
echo " • Check \"Manual proxy connection\"" | |
echo " • Enter \"localhost\" in SOCKS host" | |
echo " • Enter \"8123\" in port" | |
echo " • Click \"OK\"" | |
echo " Optional but recommended, this setting makes Firefox use the proxy server for DNS requests rather than the local client:" | |
echo " • In the search bar type \"about:config\" and press enter" | |
echo " • Search for \"socks_remote_dns\"" | |
echo " • If not already set to true double click \"network.proxy.socks_remote_dns\" to set to true" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment