14

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?

Blender
  • 1,853
  • 2
  • 18
  • 25
  • 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 04:35
  • 1
    `man lightdm` doesn't look too promising... http://www.moleberry.com/man/l/lightdm.1.html – jasonwryan Sep 30 '11 at 05: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 09: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
  • Are you trying to lock the screen while a user is logged in, or while no user is logged in? Gdm and kdm are display managers, i.e. programs that prompt for a user name and password. Did you mean the Gnome and KDE desktop environments? – Gilles 'SO- stop being evil' Sep 30 '11 at 23:10
  • See my update to this. – Evan Carroll Apr 28 '18 at 18:01

7 Answers7

11

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

Blender
  • 1,853
  • 2
  • 18
  • 25
6

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

xdg-screensaver lock

It'll take care of the gory details.

Evan Carroll
  • 28,578
  • 45
  • 164
  • 290
1

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).

rozcietrzewiacz
  • 38,754
  • 9
  • 94
  • 102
  • 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
  • 1
    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](http://manpages.ubuntu.com/manpages/hardy/man1/xautolock.1.html). – rozcietrzewiacz Oct 02 '11 at 18:07
1

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.

rohit
  • 196
  • 4
0

If the system use systemd, you can use loginctl:

$ loginctl lock-session

See more on man page.

Cirelli94
  • 283
  • 4
  • 10
0

https://wiki.archlinux.org/title/LXQt#Installation

[Screensaver]
lock_command=i3lock
吴振宇
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Luigi T. Nov 02 '22 at 10:55
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
Murz
  • 101
  • 1