I am not sure I am asking the right question, so here's what I actually want to do:

I have a server that has a screen connected to it and no other devices. It is running an SSH server.

I would like Alice to be able to connect to the server and run a command as "staff" to show a picture on the screen. For example...

ssh server sudo -u 'staff' gst-launch-1.0 playbin uri=file:///path/to/image.png

Alice goes home, and the image is still showing. Bob comes in, and decides he wants a different image:

ssh server sudo -u 'staff' gst-launch-1.0 playbin uri=file:///path/to/other.png

How does the X server need to be started and configured to meet my needs? Only the "staff" user will need to manipulate the display.

I know that I can start the server on boot using xinit and run a program of my choice. What program should I run? What should it do? Are there environment variables I will need to pass around?


In a common linux environment X server is using MIT-MAGIC-COOKIE-1 protocol to authorize access to the display. Any user who wants to access the display needs to have a correct cookie (usualy stored in ~/.Xauthority file). Normally the cookie is generated by a display manager (login screen). If you are starting X server from your custom scripts you have to generate the cookie yourself, store it in an authority file and inform the server about that file.

You can use command mcookie to generate the cookie and add it to the authority file with xauth:

# touch /home/staff/.Xauthority
# xauth -f /home/staff/.Xauthority add :0 . $(mcookie)

Prameter -f /home/staff/.Xauthority tells xauth to use authority file of the staff user. :0 is the display name. The dot (.) specifies the MIT-MAGIC-COOKIE-1 protocol. mcookie is from util-linux package.

Now if you execute:

# xauth -f /home/staff/.Xauthority list

you should see something like:

server/unix:0  MIT-MAGIC-COOKIE-1  c61bdc0b88cf0cb376e1b29647a8c4d6

When you log-in as staff user you should see the same output without -f parameter:

$ xauth list
server/unix:0  MIT-MAGIC-COOKIE-1  c61bdc0b88cf0cb376e1b29647a8c4d6

If not check that XAUTHORITY environment variable is either undefined or it is set to "/home/staff/.Xauthority".

Start the X server with -auth parameter:

# X -auth /home/staff/.Xauthority

Now staff user can access the display :0. The only thing that's left is to set the environment variable DISPLAY - this can be done via sudo parameter. So when you ssh to server and execute a command that shows an image as staff user then it should be displayed. Using ImageMagick as suggested by L. Levrel the command would be:

# ssh server sudo -u staff DISPLAY=:0 display -window root /path/to/image.png

Note you do not have to use staff user. You can create authority file in a common location (e. g. /var/tmp/xauthority) and set environment variable XAUTHORITY for Alice and Bob to that path.

Other alternative is to "distribute" the cookie to Alice's and Bob's authority files (this is actually similar to what display managers are doing):

# xauth -f /var/tmp/xauthority extract - :0 | xauth -f /home/alice/.Xauthority merge
# xauth -f /var/tmp/xauthority extract - :0 | xauth -f /home/bob/.Xauthority merge

This way Alice and Bob does not have to do sudo staff in order to access the display.

Note that if you have more X servers running you have to use different display name than :0 in the above commands (for example: :1, :2, etc.).

  • One would think that authorization should be valid only for specific instance of X server but this answer suggests one can generate authorization even without X server running… – Piotr Dobrogost Jul 24 '17 at 10:13

If you have ImageMagick installed, you can use:

display -window root /path/to/image.png

See the documentation. There are plenty of options. You will probably need at least -display.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.