Ubuntu – How to lock the screen using the new lockscreen from the command line

14.04command linelock-screenunity

Ubuntu 14.04 introduces a new lockscreen that looks similar to the login screen.

New lockscreen

I am still able to lock the screen using the command gnome-screensaver-command --lock (as I always did before), which under 14.04 does lock the screen, but:

  • If you are running it from the desktop, it locks the screen using the new lockscreen.
  • If you are running it from a virtual console or via SSH, it locks the screen using the old lockscreen.

I've also tried using xdg-screensaver lock, but it works in the same way as gnome-screensaver-command --lock does (only uses the new lockscreen when it's ran from the desktop).

Running light-locker-command --lock didn't work, as light-locker is not installed.

I guess there must be some differences between running the same command from the desktop and running it via SSH/virtual console, but I was not able to find any difference in the environment variables.

So, my question is: How can I lock the screen using the new Unity lockscreen and not the old lockscreen from the command line?

This question is probably related as it asks for the new command that needs to be used, so here's another question: Why does running the same lock command give different results?

Note that gnome-screensaver is not being used anymore in 14.04, according to this bug report:

That's not really a gnome-screensaver bug, that component stopped being used in trusty.

Best Answer

I don't have gnome-screensaver installed, and the only command I can find that works is this:

dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock