Last Updated: February 25, 2016
· hannesg

Howto use su with ssh x-forwarding

The case: I had to lunch a graphical programm on a server which is accessible via ssh ( don't ask why, the software really really insisted ). This is quite easy when using linux on server and on my machine. Just use x-forwarding in ssh ( commandline switch -X ) and the window will appear on your screen. A problem occoured when using su. This was kinda tricky, because part of x-forwarding is adding a line to the file ~/.Xauthority saying where X output may be redirected. When switching the user this line wasn't transfered to the other user and so X didn't know where to display the window. On debian servers there is one really simple solution: Use sux instead of su. This little helper programm does the transfer. However on rhel an friends this command is not installed. There you can do these steps manually:

xauth extract /tmp/x :10
su …
xauth merge /tmp/x

Et voila, you got X.