How to lock screen via command line?

Asked by Cavia Porcellus on 2014-07-02

I want to know how to bring up the lock screen via the command line. Using "dm-tool lock" comes close, but it actually does the same thing as "dm-tool switch-to-greeter" (lets you log in as a guest, certain functions, like playing music, cease). Maybe this is a bug and dm-tool lock should actually bring up the lock screen?

Question information

English Edit question
Ubuntu lightdm Edit question
No assignee Edit question
Solved by:
Cavia Porcellus
Last query:
Last reply:
Thomas Kr├╝ger (thkrueger) said : #1

gnome-screensaver-command -l

Sorry, I should have specified that I'm using Ubuntu 14.04. The gnome-screensaver method does not work (indeed, I don't even have gnome-screensaver installed, having replaced it with xscreensaver).

I'm looking to get Unity's lock screen, the same one you get by going to the cog/system menu at the top left of the Unity panel and then going to "Lock."

Thanks for the suggestion, but it just confirms that "gnome-screensaver-command -l" does not work in 14.04 and otherwise is an open question.

Yes but there are other commands in the link too.....did you try those?

I have, and have the same issues as the person who asked that question. (Note that I commented on that very question; just figured someone here might have some special insight). Thanks for your help so far though.

I guess I'll file a bug report, since I think the command "dm-tool lock" should bring up the proper lock screen.

Ah, ok, got it:
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock