0

I'm looking for a ssh client config directive like LocalForward that works as the -L CLI parameter but for the -R parameter

TL;DR full problem details

The data:

repoServer -> myComputer -> NAT -> stagingServer

I have a local git repository server that is not exposed to the internet and a remote staging server on which I have to deploy my repo.

To do so, I ssh into the remote stagingServer with a reverse socket.

Current configuration for myComputer:

File: ~/.ssh/config

Host StagingServer
  Hostname staging.acme.com
  User username
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_username
  ForwardAgent yes

on which I run: ssh StagingServer -R 8022:repository.local:22

Current configuration for stagingServer:

File: ~/.ssh/config

Host repository
  Hostname localhost
  User git
  Port 8022
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_deployer

on which I can run: git clone git@repository:myProject.git

And all works fine, but... finally

The question:

Is it possible to specify in the ssh client config file (~/.ssh/config) to open the reverse tunnel so that I haven't to add -R 8022:repository.local:22

1 Answer 1

1

Obviously what you are looking for is RemoteForward, you can find the specific in the ssh_config Doc...

Documentation: https://linux.die.net/man/5/ssh_config (Search for RemoteForward). It is self explanatory.

RemoteForward

Specifies that a TCP port on the remote machine be forwarded over the secure channel to the specified host and port from the local machine. The first argument must be [ bind_address:]port and the second argument must be host:hostport. IPv6 addresses can be specified by enclosing addresses in square brackets or by using an alternative syntax: [ bind_address/]port and host/hostport. Multiple forwardings may be specified, and additional forwardings can be given on the command line. Privileged ports can be forwarded only when logging in as root on the remote machine.

Then the configuration for myComputer becomes:

File: ~/.ssh/config

Host StagingServer
  Hostname staging.acme.com
  User username
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_username
  ForwardAgent yes
  RemoteForward 8022 repository.local:22
2
  • There is a little bit of confusion. What's obviously for LocalForward? Why then you make me look for RemoteForward? And after again an example (completely inconsistent with the example given) with LocalForward. By the way, RemoteForward is what I was looking for, I had found LocalForward and DynamicForward but didn't saw RemoteForward directive before.
    – Luca Ricci
    Jan 22, 2020 at 8:08
  • I am sorry for the confusion. Post has been updated.
    – yield
    Jan 23, 2020 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.