Last active
October 3, 2017 15:10
-
-
Save paxperscientiam/9cba7b88c98eee645899b92a2fb05e47 to your computer and use it in GitHub Desktop.
Julian Simioni's to accesss *nix machine behind home router (tweaked)
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 | |
| # 'pax' is simply an alias for one my ssh connections, | |
| # which are configured in your user ssh_config file. | |
| # For more info, see Julian Simioni's original post: | |
| # https://juliansimioni.com/blog/howto-access-a-linux-machine-behind-a-home-router-with-ssh-tunnels/ | |
| relay_server="pax" | |
| createTunnel() { | |
| /usr/bin/ssh -f -N -R 10022:localhost:22 \ | |
| -L19922:"${relay_server}":22 "${relay_server}" | |
| if [[ $? -eq 0 ]]; then | |
| echo Tunnel to relay server created successfully | |
| else | |
| echo An error occurred creating a tunnel to relay server. Return code: $? | |
| fi | |
| } | |
| # works, but reproduces until saturated | |
| #/usr/bin/ssh -p 19922 localhost ls > /dev/null | |
| # nc seems to be working better | |
| /usr/bin/nc -z 127.0.0.1 19922 > /dev/null | |
| if [[ $? -ne 0 ]]; then | |
| echo Creating new tunnel connection to relay server. | |
| createTunnel | |
| fi |
Author
works, but reproduces until saturated
Hmm I remember having that problem but I fixed it somehow. I'll try to remember why and i'll also publish my current version of the script soon
Author
Cool! I've wondered if there was some quirk to config beyond my understanding -- which is entirely probable.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
needs to be tweaked still
EDIT: should be good to go. Be sure to check out the OP by Julian Simioni.
EDIT 2:
As of this writing, I am running this script in combination with
caffeinatein the following fashion.* * * * * /usr/bin/caffeinate -ims /Users/ramos/bin/create_tunnel