50

There is no "Lock" option showing up in the user menu, and the standard shortcuts (Ctrl+L or Ctrl+Alt+L) don't do anything.

I'm running Fedora 19 with Gnome Shell 3.8.3, and XDM 1.1.11.

I'm using XDM because of broken XDMCP support in GDM - but before I upgraded to Fedora 19, I did have the lock option, even when using XDM.

I've posted an answer reflecting the results of my own research. It basically says that it's not possible to have screen-lock integrated into Gnome 3.8 without running GDM.

I really hope there's a better answer available though - so please add your own answer if there's any way to do this that I overlooked.

  • 1
    Try Ctrl + Alt + L. Does it work? – m0nhawk Aug 10 '13 at 18:07
  • 1
    @m0nhawk No, that doesn't work either. I've updated the question to reflect that. – jcsanyi Aug 10 '13 at 18:09
  • Strange, it works for me. And what is set in Settings - Keyboard - Shortcuts - System for Lock screen? – m0nhawk Aug 10 '13 at 18:10
  • @m0nhawk on Gnome 3.8 without GDM? – jcsanyi Aug 10 '13 at 18:10
  • 2
    @m0nhawk The shortcut is set to Ctrl + L - but that doesn't do anything. – jcsanyi Aug 10 '13 at 18:14

10 Answers 10

38

After some research, I think I've got enough information to post an answer to my own question.

In Gnome Shell 3.6 and earlier, the old gnome-screensaver program was present, and if GDM was not running, gnome-screensaver would be invoked - allowing you to lock the screen.

Starting in Gnome Shell 3.8 (included in Fedora 19), gnome-screensaver support has been dropped completely. This was done for three reasons: reduced code complexity coupled with the fact that the screensaver is seen as an unneeded feature, and the fact that the eventual move to Wayland will require screensaver, locking, etc. support to be in the compositor.

So the only Gnome-integrated way of locking the screen is to have GDM running, which will respond to a dbus message telling it to lock the screen. Other display managers (such as XDM) have not been designed to respond to this dbus message, and so the screen cannot be locked.


From this link:

In old versions of gnome the command gnome-screensaver-command -l would lock your screen. As gnome-screensaver is no more in gnome 3.8 you now have to send a dbus call. I think this is then handled by GDM.

$ dbus-send --type=method_call --dest=org.gnome.ScreenSaver \
    /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
  • 2
    Thanks @slim, but the commands you edited in don't actually do anything unless you're running GDM - they don't help answer the question. – jcsanyi Jan 4 '14 at 4:02
  • 2
    Sure, I'd still like to see the contents of the link brought in, in case that site goes away. – slm Jan 4 '14 at 4:09
  • @slim good point. I edited the contents back in as a quote. – jcsanyi Jan 4 '14 at 4:43
17

Super + L works in Fedora 24 which is running Gnome 3.20

  • 4
    this works on ubuntu gnome too, thanks :) – daveoncode Apr 26 '17 at 8:52
  • Also OK on Centos7 / 3.28, good to know. – tonioc Jun 6 '18 at 11:53
15

This works for me in Gnome 3.14. Standard installation, no customization.

gnome-screensaver-command --lock
  • It need to be installed in Gnome 3.26.2, so if you don't have it, sudo apt-get install gnome-screensaver. – Right leg Jun 1 '18 at 9:17
  • Did not work for me, gdm not running because a recent update broke it (had to switch to sddm...) – Per Lundberg Oct 4 '18 at 9:12
10

How to enable screen locking in Gnome Shell (3.14) using xscreensaver (on Debian):

(Note: Although the gnome-screensaver package currently exists on Debian sid, it does not seem to be usable)

  1. Install the xscreensaver package (and optionally xscreensaver-data and xscreensaver-data-extra)
  2. Run xscreensaver to configure the screensaver how you want it. Be sure to select 'Lock screen after 0 minutes'.
  3. In the GNOME keyboard settings, select the Shortcuts tab, then 'Custom Shortcuts'
  4. Click the + button, then enter whatever you want as the name and xscreensaver-command -l as the command. Click OK.
  5. Click 'Disabled' and type the key combination you would like to lock the screen (mine is Ctrl-Alt-L). Make sure this does not conflict with the GDM 'Lock Screen' shortcut under 'System'.
  6. Enjoy your lockable screen.

Caveat: Notification popups will still be visible over the locked screen. If this is a problem for you, you will need to find another solution like the LightDM Lock Screen extension.

  • 1
    Thanks for providing this option. This is the only one that ended up working for me in Gnome 3.14.1 on Debian Jessie – sanimalp Sep 8 '16 at 16:47
  • Since I wrote this answer, I have discovered a different option that involves using mate-screensaver (essentially the same as the old GNOME screensaver). This requires writing a fake session manager as described here). – Joel Cross Nov 18 '16 at 14:29
4

A work around I successfully used in debian, ubuntu and rhel7 is creating a short python script that's started automatically when you log into the gnome session. Note that in rhel7 the key combination to lock is super + l.

Create /etc/xdg/autostart/gscreenlock.py like this:

#!/usr/bin/python

import dbus
import dbus.service
import dbus.glib
import gobject
import os

class ScreenDbusObj(dbus.service.Object):
    def __init__(self):
        session_bus = dbus.SessionBus()
        bus_name=dbus.service.BusName("org.gnome.ScreenSaver",bus=session_bus)
        dbus.service.Object.__init__(self,bus_name, '/org/gnome/ScreenSaver')

    @dbus.service.method("org.gnome.ScreenSaver")
    def Lock(self):
        os.system( "xscreensaver-command -lock" )


if __name__ == '__main__':
    object=ScreenDbusObj()
    gobject.MainLoop().run()

Then make it executable:

chmod a+rx /etc/xdg/autostart/gscreenlock.py

And edit /etc/xdg/autostart/gscreenlock.desktop like this:

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=gscreenlock
TryExec=/etc/xdg/autostart/gscreenlock.py
Exec=/etc/xdg/autostart/gscreenlock.py
NoDisplay=true
NotShowIn=XFCE;KDE;
Comment=Allows screen locking in gnome
2

Screen locking was handled by gnome-screensaver up until GNOME 3.8. The application has been deprecated by the GNOME team and it functionality has been divided up among gnome-shell, gnome-session, & GDM.

If you just want to get things working you might have better luck using xscreensaver.

2

@jcsanyi gave a background explanation of how it works.

For those folks who aren't able to use GDM3 due to various reasons (say, this bug) and switched to LigthDM there is a command we can use to lock the screen(possibly it could work with other DM too, I haven't checked though) :

dm-tool lock

To make it more convenient go to settings -> Keyboard -> Scroll to the bottom -> Click "+" button -> Create new custom shortcut using the command above like this.

enter image description here

To use Super+L combination you probably have to reassign existing system Lock screen shortcut to some other combination.

  • This worked for me on Fedora 30 Gnome 3.32.2. But I wonder why my Fedora has lightdm as the default running display manager instead of GDM, and which program the default lock screen shortcut Super+L is sent to since though it's present in Settings but not working anyway. – Ivan Huang Aug 16 at 15:52
2

This answer is based on Fedora 30 GNOME 3.32.2

For Linux desktops usually the default shortcut key for locking screen is Super-L or Ctrl-Alt-L. But sometimes they may not work and you can't find a way to lock the screen. This has to do with which display manager the machine is currently running. You can check that by running $ systemctl status display-manager. If you see gdm then the default shortcut should work because this shortcut is handled by GDM - GNOME Display Manager. There are other types of display managers such as lightdm, sddm, lxdm, kdm, and xdm. The default shortcut may not work if you are running one of them. However, you can always try to lock by running $ dm-tool lock and if it works you can add a custom shortcut for this command. You may want to switch to another display manager, for example, from lightdm to gdm, and if so do below:

$ dnf install gdm
$ systemctl disable lightdm
$ systemctl enable gdm
$ reboot
0

The default shortcut is Shift+Ctrl+Alt+Lock.

You can find this, and edit using "Shortcut" tab in "Keyboard" app.

  • See comments. "The shortcut is set to Ctrl + L - but that doesn't do anything." – sourcejedi Jun 6 '18 at 11:33
  • If your answer is that this has started working again in Fedora version X even when using XDM instead of GDM, you need to specify what that version of Fedora is :). Hi and welcome to StackExchange. – sourcejedi Jun 6 '18 at 11:35
0

I figured out a workaround that works for me on Debian Buster with GNOME Shell version 3.30 and with Lightdm. I don't have any idea if this breaks anything but I haven't noticed anything unusual.

  1. Install package cinnamon-screensaver
  2. Add /usr/bin/cinnamon-screensaver to startup applications
  3. Create a keyboard shortcut for the command: cinnamon-screensaver-command -l

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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