ssh and sudo but no $DISPLAY
Another solution is to merge the .Xauthority file of the current user with that of the root user.
ssh user@host
- change the .Xauthority file permissions so that root also has access to it.
sudo su - root
xauth merge /home/users/user/.Xauthority
Test
gedit somefile.log
It should open a gedit window.
Solution found. An alternative method copied from this blog Using this script
userfirst=sshloginuser
usersecond=sudoorsuuser
$usersecond@host$
su - $userfirst -c 'xauth list' |\
grep `echo $DISPLAY |\
cut -d ':' -f 2 |\
cut -d '.' -f 1 |\
sed -e s/^/:/` |\
xargs -n 3 xauth add
Or simply Logging as user1
xauth list
su or sudo su user2
xauth add OUTPUTOFXAUTHLIST
This might be an old post, but I solved this permanently linking (in server) my sudoer user .Xauthority file with the root one:
sudo ln -s /home/userWithPrivileges/.Xauthority /root/.Xauthority
This way I don't have to do anything else ever, I can now launch any GUI app with or without sudo.