Last active
March 23, 2016 13:18
-
-
Save mnlwldr/debdae00549f8d1a06b9 to your computer and use it in GitHub Desktop.
create a ssh tunnel using autossh && random from ~/.ssh/config
This file contains 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 user config (http://www.openbsd.org/cgi-bin/man.cgi?query=ssh_config) | |
SSH_CONFIG=~/.ssh/config | |
# local port | |
PORT=8888 | |
# array with hosts from SSH_CONFIG. | |
# append "#socks5" at the end of the Host line. | |
# Example: "Host yourHost #socks5" | |
eval HOSTS=( $(awk '/^Host(.*?)#socks5$/ {print $2}' ${SSH_CONFIG}) ) | |
#HOSTS=(weidmann-prod) | |
N=1 | |
for index in `shuf --input-range=0-$(( ${#HOSTS[*]} - 1 )) | head -${N}` | |
do | |
echo -en "Host: ${HOSTS[$index]} Port: ${PORT}\n" | |
# using autossh - Automatically restart SSH sessions and tunnels | |
AUTOSSH_DEBUG=1 | |
AUTOSSH_GATETIME=0 | |
autossh -M 20000 -N -D ${PORT} ${HOSTS[$index]} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment