1

Here is a script which is run in cron for user1 who has sudo privileges

   export DISPLAY=:0 
   export XAUTHORITY=/home/user2/.Xauthority 
   scrot -q 30 "/tmp/%Y-%m-%d-%H-%M_screen.jpg" 2>/tmp/err
 

It worked fine on Ubuntu 16.04. When upgraded to 18:04, it gives the error: Invalid MIT-MAGIC-COOKIE-1 keygiblib error: Can't open X display. It is running, yeah?

File .Xauthority is owned by user2, group owned by user1 and has permissions 660.

What changed between Ubuntu 16:04 and 18:04? I tried export DISPLAY=:1.0 instead of export DISPLAY=:0 after reading a post on SO. It gave this error: giblib error: Can't open X display. It is running, yeah?

Sunny
  • 381
  • 1
  • 6
  • 16

1 Answers1

1

From the ArchWiki:

Invalid MIT-MAGIC-COOKIE-1 key when trying to run a program as root

That error means that only the current user has access to the X server. The solution is to give access to root:

$ xhost +si:localuser:root

That line can also be used to give access to X to a different user than root.

So you probably need to execute on the host:

$ xhost +si:localuser:user1

Henrik Pingel
  • 9,380
  • 2
  • 28
  • 39
  • Yes, that did it. Thanks. But why was it working on 16.04 without this line? 18.04 broke a few things for me. netplan for one... – Sunny Jul 08 '20 at 19:53
  • I doubt that the x11 authentication mechanism changed dramatically between Ubuntu 16.04 and 18.04. Most likely that setting was set manually on the 16.04 system or set by a script not present in 18.04. – Henrik Pingel Jul 08 '20 at 20:04