Skip to content

Instantly share code, notes, and snippets.

@bltavares
Last active September 5, 2016 17:22
Show Gist options
  • Select an option

  • Save bltavares/ff223dfec82d5f888b2af62c882e82af to your computer and use it in GitHub Desktop.

Select an option

Save bltavares/ff223dfec82d5f888b2af62c882e82af to your computer and use it in GitHub Desktop.

Revisions

  1. bltavares revised this gist Sep 2, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions README.org
    Original file line number Diff line number Diff line change
    @@ -28,10 +28,10 @@ So, what this setup do, is to use a third computer as a middle ground, and setup
    First, one computer connects to the proxy server, and forwards its ssh 22 port to another port exposed publicaly.

    #+BEGIN_SRC sh
    ssh -R 0.0.0.0:5567:localhost:22 tty.space
    ssh -R 0.0.0.0:5567:localhost:22 example.com
    #+END_SRC

    This will create an ssh connection between me and ~tty.space~, and forward all requests on ~tty.space:5567~ to my computer on ~localhost:22~.
    This will create an ssh connection between me and ~example.com~, and forward all requests on ~example.com:5567~ to my computer on ~localhost:22~.

    *Note:* The ssh server needs to be configured to allow the port to be exposed publicly. Add the following option on the sshd configuration

    @@ -42,7 +42,7 @@ This will create an ssh connection between me and ~tty.space~, and forward all r
    Then, the second computer connects to the exposed port, that will point directly to mine local ssh.

    #+BEGIN_SRC sh
    ssh username-on-my-computer@tty.space -p 5567
    ssh username-on-my-computer@example.com -p 5567
    #+END_SRC

    This will use the exposed port to authenticate on mine ssh server, running here, where I'm typing.
  2. bltavares revised this gist Sep 2, 2016. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions README.org
    Original file line number Diff line number Diff line change
    @@ -28,15 +28,21 @@ So, what this setup do, is to use a third computer as a middle ground, and setup
    First, one computer connects to the proxy server, and forwards its ssh 22 port to another port exposed publicaly.

    #+BEGIN_SRC sh
    ssh -R 0.0.0.0:5567:localhost:22 example.com
    ssh -R 0.0.0.0:5567:localhost:22 tty.space
    #+END_SRC

    This will create an ssh connection between me and ~example.com~, and forward all requests on ~example.com:5567~ to my computer on ~localhost:22~.
    This will create an ssh connection between me and ~tty.space~, and forward all requests on ~tty.space:5567~ to my computer on ~localhost:22~.

    *Note:* The ssh server needs to be configured to allow the port to be exposed publicly. Add the following option on the sshd configuration

    #+BEGIN_SRC conf :file /etc/ssh/sshd_config
    GatewayPorts clientspecified # Allow reverse ssh tunnels
    #+END_SRC

    Then, the second computer connects to the exposed port, that will point directly to mine local ssh.

    #+BEGIN_SRC sh
    ssh username-on-my-computer@example.com -p 5567
    ssh username-on-my-computer@tty.space -p 5567
    #+END_SRC

    This will use the exposed port to authenticate on mine ssh server, running here, where I'm typing.
  3. bltavares revised this gist Sep 2, 2016. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions README.org
    Original file line number Diff line number Diff line change
    @@ -67,6 +67,23 @@ It is possible to set the ssh configuration to make the persson jump right into

    You can change the command to whatever you want that key to execute when connecting to the computer.

    One more thing:

    ** Tell me!

    It is possible to access any port exposed locally from your computer using this tunnel!

    So, let's say I'm running a webserver on ~localhost:3000~.

    When you try to access the webserver typying that on your browser it won't work :/
    But we can fake it!

    When connecting, you can add the =-L= option, and forward any ~localhost:3000~ on your computer to mine.

    #+BEGIN_SRC sh
    ssh -L 3000:localhost:3000 username-on-my-computer@example.com -p 5567
    #+END_SRC

    ** Thank you!

    Come back again! (:
  4. bltavares created this gist Sep 2, 2016.
    72 changes: 72 additions & 0 deletions README.org
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    * How to remote pair, over SSH?

    ** If you are capable of direct access
    Just connect; Done;

    ** But... I'm behind NAT, and Firewalls and everything!

    I thought so... The internet is not that easy of a place huh?!
    They told everybody would be connected, and promised again with IPv6, but I'm disgressing.


    So, you want to connect to someone, and both of you are behind your corp firewall?

    ** Yup

    What about a proxy ssh connect?

    ** If it works, that would be nice!

    So, what this setup do, is to use a third computer as a middle ground, and setup a quick ssh connection between you two.

    #+BEGIN_EXAMPLE
    My computer ---ssh---> proxy server
    <------------ssh------------ Your computer
    #+END_EXAMPLE


    First, one computer connects to the proxy server, and forwards its ssh 22 port to another port exposed publicaly.

    #+BEGIN_SRC sh
    ssh -R 0.0.0.0:5567:localhost:22 example.com
    #+END_SRC

    This will create an ssh connection between me and ~example.com~, and forward all requests on ~example.com:5567~ to my computer on ~localhost:22~.

    Then, the second computer connects to the exposed port, that will point directly to mine local ssh.

    #+BEGIN_SRC sh
    ssh username-on-my-computer@example.com -p 5567
    #+END_SRC

    This will use the exposed port to authenticate on mine ssh server, running here, where I'm typing.

    Voilà!

    ** Sweet! Connection is setup! What about password?

    You can either share the password (DON'T), or authorized the access adding the public key to =~/.ssh/authorized_keys= file.

    ** How can I get the public key?

    The key is usually stored on =~/.ssh/id_*.pub=, but there is a nice tip.

    Accessing the profile on GitHub and appending =.keys= will give you that persons public keys!
    Like so: https://github.com/bltavares.keys

    This is not a problem. Remember, those keys are supposed to be public!

    ** Any other tip?

    Yup. Many times you will be spawning shells to pair, so you will be using a terminal multiplexer, like ~screen~ or ~tmux~.
    It is possible to set the ssh configuration to make the persson jump right into the open session.

    #+BEGIN_SRC text :file ~/.ssh/authorized_keys
    command="/usr/local/bin/tmux attach -t 1" ssh-rsa ASDF...
    #+END_SRC

    You can change the command to whatever you want that key to execute when connecting to the computer.

    ** Thank you!

    Come back again! (: