Connecting to an X11 display requires two pieces of information: the display name (normally passed in the
DISPLAY environment variable) and the cookie, which is a password for the display that every application must show when connecting. Typically the cookie is stored in
~/.Xauthority, but it can be stored in a different file indicated by the
XAUTHORITY environment variable.
It appears that the value of
DISPLAY set by SSH was preserved by the two calls to
su. However the cookie is in
~mahmood/.Xauthority; when you run a program as hmousavi, the program looks for a cookie in
~hmousavi/.Xauthority and finds a different value.
In principle you could run
XAUTHORITY=~mahmood/.Xauthority xclock, but hmousavi presumably doesn't have the permission to read that file — the
.Xauthority file should not be readable to other users. You can use the
xauth command twice, once as mahmood to extract the cookie value (
xauth list localhost:10.0) and once as hmousavi to import that value (
xauth merge), but that's cumbersome. The easiest way to make X11 applications work is to use SSH all the way, because SSH sets up X11 forwarding automatically:
mahmood@cluster:~$ ssh -X hmousavi@localhost
Add mahmood's SSH public key to hmousavi's
.ssh/authorized_keys to allow this.