Ubuntu – screen is not locked after suspend/lid closed

lock-screensuspend

My screen doesn't get locked after I close my laptop lid. The laptop suspends but the screen is not locked.

I checked multiple settings:

gnome-control-center > brightness & lock > lock on and require password when waking from suspend enabled
dconf-editor > org/gnome/desktop/lockdown/disable-lock-screen disabled
dconf-editor > org/gnome/desktop/screensaver/lock-enabled enabled
dconf-editor > org/gnome/desktop/screensaver/ubuntu-lock-on-suspend enabled

But can't get to lock my screen after suspend. What else can I try?

Best Answer

Not a solution, but you may use this script as a workaround:

#!/bin/bash
qdbus com.canonical.Unity /com/canonical/Unity/Session com.canonical.Unity.Session.Lock &&
qdbus com.canonical.Unity  /com/canonical/Unity/Session com.canonical.Unity.Session.Suspend

This works with stock Ubuntu with Unity desktop. The approach is specific to Unity, although there are dbus calls to suspend regardless of the desktop environment. For 16.04 , one could use systemctl suspend command. See the relevant post: https://askubuntu.com/a/1795/295286

Alternative (older answer, edited)

One of the other tools for suspending, that works regardless of the Ubuntu version is pm-suspend. Problem is that it requires root privilege. To work around that, add pm-suspend to /etc/sudoers file to be executed without password ( more info here ).

In particular, in my /etc/sudoers I have the following:

# Allow using pm-suspend for my user without password
serg ALL = NOPASSWD: /usr/sbin/pm-suspend

Thus, you can use:

sh -c 'gnome-screensaver-command -l && sudo pm-suspend'

The sudo pm-suspend won't prompt you for password then.

Related Question