0

So root invoked some script, and specific user session should be locked. I managed to get this working before, but now I cannot win.

Currently I'm following this article: https://0day.work/locking-the-screen-when-removing-a-yubikey/ everything is just fine only to last step, actual locking.

this command is invoked:

# echo $DISPLAY
:0

# echo $XAUTHORITY
/home/mmucha/.Xauthority

# su "mmucha" -c "/usr/bin/gnome-screensaver-command --lock"
Can't connect to screensaver!

same for:

runuser -l mmucha -c 'export DISPLAY=:0;export XAUTHORITY=/home/mmucha/.Xauthority;gnome-screensaver-command -l'

what am I missing?

EDIT: ubuntu 18.04, running cinnamon-desktop, however this probably does not have any influence. It does not work equally for cinnamon-screensaver-command and for gnome-screensaver-command.

Martin Mucha
  • 215
  • 3
  • 11
  • it's gnome, but actually I'm using cinnamon desktop which I added, which has it's own screensaver. But I can launch gnome-screensaver-command as well from cinnamon desktop. And neither can be launched as demonstrated from root shell. Both can be run as the user which is logged in. – Martin Mucha Nov 07 '19 at 22:42
  • This thread talks about using a different command for cinnamon desktop: cinnamon-screensaver-command -l and also make sure the screensaver is actually running. – Joaquín Ayuso de Paúl Nov 07 '19 at 23:53
  • yep, I know about cinnamon-screensaver-command. I tried both variants. Logged in user can run that command and lock will occur. Root user cannot. – Martin Mucha Nov 08 '19 at 10:43
  • well, I was also facing the same problem and have found this post. Looks like the actual solution is not posted anywhere. But finally I was able to perform the action, the problem was in 'XDG_RUNTIME_DIR' variable, so something like
    su user -c 'XDG_RUNTIME_DIR=/run/user/1000 gnome-screensaver-command -l' 
    
    

    should work

    – Nick Oct 27 '22 at 11:16

0 Answers0