Locking the screen via CLI?

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


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

xdg-screensaver lock

It'll take care of the gory details.