Skip to content

Instantly share code, notes, and snippets.

@crowjdh
Last active September 3, 2021 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crowjdh/00a8b7b4c492b309d0facd74c3b58dcd to your computer and use it in GitHub Desktop.
Save crowjdh/00a8b7b4c492b309d0facd74c3b58dcd to your computer and use it in GitHub Desktop.
|---------------|                   
|               |                   |---------------|
|               |                   |               |
|      Host     |  1. SSH Tunnel    |               |
|     Behind    |==================>|      My       |
|  Firewall(A)  |<------------------|   Device(B)   |
|               |  2. Reverse SSH   |               |
|               |==================>|               |
|---------------|                   |---------------|

1. Host Behind Firewall(A)

  • Install & run SSHD
  • SSH from A into B
# -N: -Do not execute a remote command.  This is useful for just forwarding ports.
# -f: Requests ssh to go to background just before command execution.
ssh [-Nf] -R B_PORT:localhost:A_SSHD_PORT B_USER@B_IP

2. My Device(B)

  • SSH from B into A via tunnel we made above
ssh -p B_PORT A_USER@localhost

Misc

  • Kill background SSH tunnel
ps aux | grep ssh
kill -9 PID
  • List ports that are currently listening
netstat -tulpn | grep LISTEN
  • ???
nc -l -p SOME_PORT

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment