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
  2. List your xauth

    $ xauth list  MIT-MAGIC-COOKIE-1  c11dec3114034d20d92e839581bc7a2c  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  MIT-MAGIC-COOKIE-1  ccf459946111123cf8d111cc6795d3e8
  7. Run your remote GUI app

    remoteuser $  ./someLameGUI
Andrew Martin
Lead BI Infrastructure Architect
comments powered by Disqus