Today is: 11 March, 2010

Allow X Forwarding over SSH while using sudo

If you want to sudo, but then allow X Forwarding over SSH, I've found the easiest way is to copy the xauth information from the logged in user to root.
For example:

  1. Enable X-11 Forwarding in your client
  2. Log in as your normal user
  3. Type `echo $DISPLAY` to get the associated display
  4. Type `xauth list` find the display number which corresponds with what you found in #3 and copy it
  5. Sudo to root
  6. Type `xauth add <paste in what you copied from #4>`
  7. Now you can execute commands as root and will be able to use the X11 Forwarding connection established by the parent user