Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rbeer
Last active May 20, 2017 22:12
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 rbeer/985d15a9cecac797ddf0a9172f238683 to your computer and use it in GitHub Desktop.
Save rbeer/985d15a9cecac797ddf0a9172f238683 to your computer and use it in GitHub Desktop.
ssh -L example

$ ssh yourhost.com -L 7000:localhost:6379

 -----                         ----------------                          -----------------                         --------------
| RDM | -- localhost:7000 --> | OpenSSH, `ssh` | -- yourhost.com:22 --> | OpenSSH, `sshd` | -- localhost:6379 --> | redis-server |
 -----                         ----------------                          -----------------                         --------------
                (1)                                       (2)                                        (3)
  1. RDM connects and sends data locally on port 7000 to the OpenSSH process - unencrypted
  2. OpenSSH encrypts the data and sends it to your destination host on port 22.

(-- internet --)

  1. OpenSSH receives the data on the remote host and decrypts the stream. Then sends the clear text data locally to the redis-server instance on port 6379.
@rbeer
Copy link
Author

rbeer commented May 20, 2017

You can shorten the command to something like ssh redis-tunnel, if you create a Host redis-tunnel entry in your ~/.ssh/config:

Host redis-tunnel
    HostName yourhost.com
    # http://man.openbsd.org/ssh_config#IdentitiesOnly
    IdentitesOnly yes
    User remote-redis
    IdentityFile ~/path/to/your/private/remote-redis@yourhost.com.key
    # The tunneling
    # http://man.openbsd.org/ssh_config#LocalForward
    LocalForward 7000 localhost:6379

Use this config with ssh redis-tunnel and then connect to localhost:7000 with your client.

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