21

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.

2
  • 2
    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.
    – Fern Moss
    Jun 30, 2014 at 22:58
  • 2
    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, 2014 at 12:48

4 Answers 4

17

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

6
  • 5
    qdbus org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock Aug 2, 2014 at 0:37
  • This used to work, but it seems not to work anymore in 15.10 :/
    – Léo Lam
    Jan 16, 2016 at 13:18
  • 1
    @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
    – Fern Moss
    Jan 17, 2016 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, 2016 at 18:09
  • 1
    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 Apr 1, 2016 at 8:30
3

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

2
  • 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, 2016 at 11:39
  • Worked for me remotely in an SSH session into an 18.04 LTS machine.
    – Benjamin R
    Mar 11, 2019 at 11:09
3

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.

4
  • 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, 2016 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. Apr 1, 2016 at 17:39
  • Try running dbus-launch --exit-with-session gnome-terminal before that. serverfault.com/a/411326 Apr 1, 2016 at 17:41
  • Can also connect to a screen/tmux session running inside X and run the command from there. Was my final workaround to connect to the right dbus session from a vterm.
    – Iiridayn
    Jan 25, 2018 at 20:49
2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .