Skip to content

Instantly share code, notes, and snippets.

@bltavares
Last active September 5, 2016 17:22
Show Gist options
  • Save bltavares/ff223dfec82d5f888b2af62c882e82af to your computer and use it in GitHub Desktop.
Save bltavares/ff223dfec82d5f888b2af62c882e82af to your computer and use it in GitHub Desktop.
How to remote pair over SSH

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.

My computer  ---ssh---> proxy server
             <------------ssh------------ Your computer

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

ssh -R 0.0.0.0:5567:localhost:22 example.com

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

GatewayPorts clientspecified # Allow reverse ssh tunnels

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

ssh username-on-my-computer@example.com -p 5567

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.

command="/usr/local/bin/tmux attach -t 1" ssh-rsa ASDF...

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.

ssh -L 3000:localhost:3000 username-on-my-computer@example.com -p 5567

Thank you!

Come back again! (:

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