After logging in as another user how do I run GUI programs?
thufir@doge:~$ sudo -u hawat -i
hawat@doge:~$ echo $HOME
No protocol specified
Failed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :0
For convenience, I created a wrapper bash script, that you might want to download to /usr/local/bin/xsudo and mark executable (chmod +x /usr/local/bin/xsudo).
Then simply run:
xsudo hawat firefox
As a far simpler alternative, you might look into pam_xauth (s. this answer) However this doesn't work for me for some reason. (I still get the error about firefox not being able to connect to the display at :0)
In a lot of forums you might see the command xhost +local: or similar, which will make gksudo -u hawat firefox work without any wrapper script. However be aware that this opens a security loophole: Any active user on your local host will be able to access your keyboard, mouse, screen etc.
There used to be sux, which has been discontinued for some reason - you might still be able to download and use it though. As far as I can tell, it did something similar to my script only a lot more. Unfortunately I couldn't find out, why this is no longer maintained. (Maybe because we should now use pam_xauth instead - s. first alternative)