Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
I would like to know as well. Using dm-tool lock comes close: it locks the screen, but (unlike the default Unity lock screen) also allows you switch users. – Aibara Iduas Jun 30 '14 at 22:58
dm-tool lock and dm-tool switch-to-greeter seem to be doing the same thing: take you back to the log in screen (greeter), which does look very similiar to the lockscreen. – Léo Lam Jul 2 '14 at 12:48
up vote 9 down vote accepted

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

share|improve this answer
qdbus org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock – Aquarius Power Aug 2 '14 at 0:37
This used to work, but it seems not to work anymore in 15.10 :/ – Léo Lam Jan 16 at 13:18
@LéoLam Are you using a livecd image? I'm still using 14.04, but I did test both my command and Aquarius Power's in 15.10 and got them to work. However, I had to enable the lock screen to get it to work via this command gsettings set org.gnome.desktop.lockdown disable-lock-screen false – Aibara Iduas Jan 17 at 22:22
Nope, it's on a real Ubuntu install. gsettings get org.gnome.desktop.lockdown disable-lock-screen returns false. Now there's no output at all when running dbus-send. Maybe gnome-screensaver is needed for this to work? – Léo Lam Jan 18 at 18:09
See my answers please, perhaps 15.10 has abandoned using the org.gnome.ScreenSaver dbus interface , so it's probably better idea to communicate with Unity's dbus interface – Serg Apr 1 at 8:30

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.

share|improve this answer
this does work in a graphical session, but fails in a SSH session even when setting $DISPLAY manually. "Service 'com.canonical.Unity' does not exist.". – Léo Lam Apr 1 at 17:12
This has nothing to do with DISPLAY variable , but with dbus. I'm not aware of whether over ssh Unity doesn't have a dbus session or not , so I can't help you in that part. I will ask around but so far that's as much as i can say. – Serg Apr 1 at 17:39
Try running dbus-launch --exit-with-session gnome-terminal before that. – Serg Apr 1 at 17:41

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

share|improve this answer
It is mentioned in the OP that it does not work in all cases. Only when you're running it locally in a terminal from the GUI. – Léo Lam Jan 23 at 11:39

You can always send the keystrokes: xdotool key super+l.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.