SSH – How to SSH -Y and Then su – and Forward X Applications

ssh-tunnelingsux11

It is easy enough to 'fetch' (ie draw locally) a remotely running linux application: If I ssh -Y to the remote machine and run an application, that application will surely enough pop up in my local desktop.

If , however, while I am ssh'ed in the remote machine, I su to a different user, I can not forward the X application to my local machine. It says wrong authentication.

I am not sure how to tackle this case. The echo $DISPLAY is still correct (set by the initial ssh -Y logon), but the session cookie is probably only set for the initial user that logged on ssh.

How can I overcome this difficulty and forward other X applications that are run from different users?

The reason I am not ssh'ing directly is because I don't want that user to be accessible through ssh (it is the "virtualbox" user, which is obviously an easy target for bots trying to ssh to that server)…

Best Answer

When you connect to a remove machine via ssh with X11 forwarding enabled, ssh on the server creates a .Xauthority file in the user's home directory. Because ssh listens for X11 on a TCP socket, anyone can connect. Because anyone can connect, we need some way of preventing just anyone from using your display. This is done with that .Xauthority file. The file contains a "cookie" which is presented to the X11 server that verifies the client should be allowed to connect.

Skipping all the details, if you copy that .Xauthority file to your target user's home directory (and give them ownership), you should be able to connect.

Related Question