How do I forward X when switching users?

I can ssh -X [email protected] and open GUIs just fine. However, then when I sudo su to root, the X11 forwarding seems to stop because the windows never seem to launch.

ssh access is disabled for root, otherwise I would just connect directly.

  • if ssh for root is disabled then how can you use x11 forwarding for root?
    – Ijaz Ahmad
    Commented Jan 4, 2016 at 17:46

1 Answer 1


You would need to set up the magic cookies and the DISPLAY environment variable appropriately. While the latter is done easily, the latter is a bit more complicated. In some cases using insecure forwarding ssh -Y might be a solution, but I generally advise against the X11 over SSH. In most cases it is better to use VNC.

Not the answer you're looking for? Browse other questions tagged .