Issue:
You are logged into your desktop but you need to run another X-windows process that as a different user. eg. Hexchat whilst logged in as root (mostly Kali related.)
Hexchat and potentially other applications may pop up a helpful prompt letting you know not to run things as root as it is a ‘Bad Thing™’
Glorious message isn’t it!
Problem being that the user does not have permission to run on the current display. X windows will check a file named Xauthority to see if that user has permission to spawn a process on the current display.
Solutions:
In a terminal type the following:
xhost + SI:localuser:muh
gksudo -u muh hexchat #Or su - muh -c hexchat
xhost is a command that gives authority for hosts or users to access your X environment and run apps in the session. The SI section means Server Interpreted and as localuser with username muh. Essentially SI:<hostname>:<username> Note: This lasts only for the duration of your X session. So rebooting would remove this.
gksudo much like sudo but for X. The switch -u is for user (username being muh in this instance) This should start Hexchat or which ever application you need. If you are not root you will be prompted for a password of the user. And that’s it.
Update April 7th 2019 : Add export DISPLAY=:0.0 into ~/.bashrc for the user you want to run the application as.
Hope this was useful for someone out there.
GRL.