Ok, the title might be a bit confusing so here's what I'm trying to achieve.

I have multiple machines of types A that would connect to a server B. All machines of type A would have some kind of GUID.

What I'm trying to achieve is that machine A would initiate a SSH tunnel to server B then someone from his personal computer can connect to machines of type A through server B.

I'm able to port forward it like this:

ssh -R 3000:localhost:22 server_host -p 58122

But that's not really convenient as I'd have to guess an unused port.

I'd rather have something like this:

ssh -R /tmp/nodes/${guid}.sock:localhost:22 server_host -p 58122

Then something like this from the server B:

ssh /tmp/nodes/${guid}.sock

But the first command always return this:

Warning: remote port forwarding failed for listen path /tmp/guid.sock

As if the socket couldn't be created. The ssh client connect to the server B but cannot initiate a socket for its own ssh port.

The main goal is to be able to create a SSH tunnel from the node machines A to the server B. The reason is that those machines are hidden behind a network and there is no real other way to create a tunnel from Server B to nodes A.

I'm not even sure ssh can connect directly to a socket so if there is an alternative to port forwarding I'd be happy to know.

  • A VPN may be the wheel you're trying to reinvent. – Kamil Maciorowski Sep 18 '18 at 10:16
  • Note: you got remote port forwarding failed probably because there is /tmp/guid.sock on B from your previous try. The fact a socket gets left behind will complicate your procedure. Connecting to a valid socket is possible. – Kamil Maciorowski Sep 18 '18 at 10:27
  • The socket was never created so no, I think the problem is in a configuration. I ended up with something working on 2 of my machine locally. – Loïc Faure-Lacroix Sep 18 '18 at 10:29
  • As for the VPN, it may be a solution but we'd have to create a VPN for each client and have a way to configure the VPNs remotely, that said it kind of simplify how to ssh the nodes. – Loïc Faure-Lacroix Sep 18 '18 at 10:30
  • "to create a VPN for each client" -- Why? Before you answer, read this. – Kamil Maciorowski Sep 18 '18 at 10:32

You could try and use ssh tunnel and socat.


Here is a script to inspire you.

  • That answer would benefit from more details instead of a link for inspiration. – RalfFriedl Nov 17 '19 at 0:14
  • Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change. – DavidPostill Nov 17 '19 at 1:20

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.