How can I lock the screen using the new lockscreen from the command line?

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


The accepted answer has the right idea, except that the lockscreen is related to unity panel, while org.gnome.ScreenSaver is obviously a Gnome-related type of schema,so it may or may not work.

There exists however a dbus interface for Unity, and all we need is to call this method com.canonical.Unity.Session.Lock like so

qdbus com.canonical.Unity  /com/canonical/Unity/Session com.canonical.Unity.Session.Lock

Side note:

The proof of the fact that it's related to unity panel is simple, when you have the screen locked, the process /usr/lib/unity/unity-panel-service will change to /usr/lib/unity/unity-panel-service --lock-mode as observed from tty1.


I recently found out that xdg-screensaver lock works aswell and is quite a simple solution too!