I have a setup where I need to forward X11 from my local machine (laptop) to a Virtual machine. The server hosting this VM cannot be reached directly from my laptop. I need to first login to a gateway and from this gateway, I can access the VM. How can I forward X11 from my laptop to this VM? I have tried following but these do not work:

  1. [laptop # ] ssh -X [gateway]

    [gateway # ] ssh -X [VM]

  2. [laptop # ] ssh -tX [gateway] ssh -X [VM]

I could forward X11 only till the gateway. (DISPLAY variable gets set on gateway)


1 Answer 1


What you need to do is to use port forwarding so that you can ssh to the remote machine via port forwarding and then do ssh -X.

ssh -L 2222:[VM]:22 [gateway]
ssh -p 2222 -X localhost


ssh -R 2222:[VM]:22 [gateway]
ssh -p 2222 -X [gateway]

You must log in to answer this question.