/ linux

su with X forwarding


Recently I started working more on linux systems that require X windows
to run, mostly due to GUI installers. I am not new to the idea of X
forwarding over SSH, and I am not new to the idea that some installers
must be run as certain users — But this was a first for me where the
graphic installer had to be run on a remote machine, and had to be run
as a user with no password.

My Setup

Running Mac 10.9.2 (Mavericks)

Standard Mac Terminal with XQuartz for my X windows display


  1. Login to your remote server

     ssh -X user@remotehost.com
  2. List your xauth

     $ xauth list
     remotehost.com/unix:10  MIT-MAGIC-COOKIE-1  c11dec3114034d20d92e839581bc7a2c
     remotehost.com/unix:11  MIT-MAGIC-COOKIE-1  ccf459946111123cf8d111cc6795d3e8
  3. If more than one are listed echo your DISPLAY

     $ echo $DISPLAY
  4. Select and copy the correct line

  5. Switch user

     $ sudo su - remoteuser
     [sudo] password for user:
     remoteuser $
  6. Add the xauth

     remoteuser $  xauth add remotehost.com/unix:11  MIT-MAGIC-COOKIE-1  ccf459946111123cf8d111cc6795d3e8
  7. Run your remote GUI app

     remoteuser $  ./someLameGUI