SSH X Forwarding when using Sudo

When you ssh -X to a host, SSH handles X forwarding for you. However, if you run a sudo command in that session, the process breaks down. Here’s how you can make it work:

you@local$ ssh -XC server
you@server$ xauth list
 [output]
you@server$ sudo su - otheruser
otheruser@server$ xauth add [paste output from "xauth list"]
otheruser@server$ xterm (or other X application)

Source: http://backdrift.org/x-forwarding-sudo-ssh-session