7

Is there any way that I can lock the screen CLI-style? I'm trying to target as many desktop managers as possible (mostly LightDM, but GDM, KDM, SLiM, XScreensaver, etc. would be great too), but I can only dig things up for GDM and XScreensaver.

For GDM, it would be:

gnome-screensaver-command -l

For XScreensaver:

xscreensaver-command -lock

Is there a similar command for KDM and LightDM?

  • Can you start the screen saver and ssh in and ps and see what screen saver is running and deduce from there what command to run? (how I found the gnome-screensaver-command) – polynomial Sep 30 '11 at 4:35
  • 1
    man lightdm doesn't look too promising... moleberry.com/man/l/lightdm.1.html – jasonwryan Sep 30 '11 at 5:41
  • Perhaps you can try to control them via d-bus (using dbus-send to send the appropriate lock message). – andcoz Sep 30 '11 at 9:24
  • @andcoz: I saw a few dbus-send things while Googling, but sadly none of them worked. I even looked at the LightDM API reference for a solution, but even that doesn't have anything. Heck, I even tried to look at the source of Ubuntu's user switching panel (sorry, can't read like 1,000,000 of C). I might try emailing the dev list for help... – Blender Sep 30 '11 at 15:48
  • @polynomial: That seems like a good solution (maybe post it as an answer?). I don't have a second computer to SSH with, but I can try and print the process list every second or so to deduce what is happening. – Blender Sep 30 '11 at 15:51
9

I Googled/emailed around a bit and got these two commands.

To lock the screen:

xflock4

To activate user switching:

gdmflexiserver

For Lightdm, this file resides in a strange spot (at least on Arch Linux):

/usr/lib/lightdm/lightdm/gdmflexiserver

I merged these two into XFCE's logout button dialog, in case anyone's interested, so the patch is available here: https://aur.archlinux.org/packages.php?ID=52816

  • Xflock4 must have gnome-screensaver – Prvt_Yadv Apr 28 '18 at 19:29
2

You can lock all screen savers on X by using xdg-screensaver

xdg-screensaver lock

It'll take care of the gory details.

0

There are several DM-independent, simple solutions like alock, slock or xtrlock (manpage). Note that they might not even display any input window prompting for password - you just enter the password while the screen is blank and press Enter (that's the case of slock at least).

If you want the locker to be able to display a screensaver and show a custom prompt on un-locking, try xlock provided with xlockmore package (see this info and the manpage).

  • I'm not looking for a lock screen (I have my own, plock, for that :P). I'm looking for a way to trigger the lockscreen (whatever it is). – Blender Sep 30 '11 at 15:47
  • Then xautolock (which is a part of xlockmore) provides this functionality - have a look at the last two links I posted and the xautolock manpage. – rozcietrzewiacz Oct 2 '11 at 18:07
0

This is not pretty, but working solution for unlock kde or lightdm session from screensaver via cli (command line):

qdbus | grep kscreenlocker_greet | xargs -I {} qdbus {} /MainApplication quit
0

For a environment agnostic lock app, there is i3lock which also lets you set the lockscreen background.

For LightDM you can run light-locker as a background process in your session. It will lock your session as soon as the screensaver starts/system resumes from suspend.

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.