Without being the person logged in at the console, how do I run an X application and have it display on that X session? Assume I am either root, or I am the same user who logged in, so in principle I have persmission to do this. But how do I convince X of this?
Some examples of situations like this:
- Log in with SSH and run a program that displays on the remote computer’s screen (not tunneled through SSH—that is totally different)
- A cron job to take a screenshot of the X session via ImageMagick’s
importcommand - Running a keystroke logger for audit purposes
This is a simpler version of Launch OpenGL app straight from a windowless Linux Terminal
The short answer is that you have to set the
DISPLAYenvironment variable, and then the app will run.The long answer is that we’ve got Xauth, and unless you’re running as the same user on the same machine that’s probably not going to work unless you export the Xauth credential from the account running the X server to the account running the X client.
ssh -Xhandles this for you, which is why it’s awesome, but the manual procedure involves runningxauth extract - $DISPLAYon the X server account and feeding that data intoxauth merge -on the client account. (Warning: the data is binary.)On modern Linux systems, there is one X session at :0 and the X11 authority data file is always
$HOME/.Xauthorityso you can most often set two environment variables, for example, in Bash: