-1

Is SSH X forwarding an example of remote port forwarding? I feel like so.

How can SSH X forwarding be done in terms of SSH remote port forwarding command?

Thanks.

enter image description here

  • I need to double check, but I think it forwards a unix domain socket. It's remote... but not a port. – Philip Couling Feb 6 at 22:01
  • You are confusing. Isn't a port part of a socket ? Or only internet socket has port? – Tim Feb 6 at 22:02
  • No. Look up "Unix domain sockets". Instead of a port number and IP you open a file. They are only for connections on the same box. Allowing one app to talk to another on the same machine. – Philip Couling Feb 6 at 22:39
2

The underlying communication is very similar to ssh -R6010:localhost:6000... but the X forwarding in SSH does a lot more magic in the background.

For example, what if there was already a service listening on port 6010? SSH will try 6011, 6012.. until it finds a free port.

Then you need to set the DISPLAY variable on the remote end. Which may be localhost:10.0 or localhost:11.0 or... depending on the remote port picked up.

Then you need to handle X authentication (xauth) to ensure the client sends the right magic cookie expected by the local X server...

With more modern ssh servers and clients the connection may be to/from unix domain sockets instead of TCP sockets, but the concept is still the same.

Basically, the X options of ssh handle a number of the "house keeping" requirements for an X session... as well forwarding traffic.

  • Tim, see also this question regarding the relationship between port numbers and display numbers. – Stephen Kitt Feb 7 at 6:27
  • "With more modern ssh servers and clients the connection may be to/from unix domain sockets instead of TCP sockets" No, it isn't. Do you have an example? – mosvy Feb 7 at 6:28
  • @mosvy that was to address the case where the local X server may only have a unix domain socket, and so the solution isn't necessarily the same as forwarding 6010->6000, but may be closer to 6010->/tmp/.X11-unix/X0 – Stephen Harris Feb 7 at 11:40
  • since that hasn't changed since quite a while, your statement gives the false hope that ssh is now able to listen on unix sockets for x11 forwarding instead of tcp 60XX, and that it's no longer only relying on the "security" offered by the X11 protocol. That's not the case yet -- unfortunately. – mosvy Feb 7 at 12:04

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.