Lock the screen when user is idle

If you want to enable the screensaver and make the screen lock automatically when the user is idle, you need to create a dconf profile, set the GSettings key pairs and then lock it to prevent users from editing it.

Enable the screensaver

To enable the screensaver and lock the screen, follow this procedure:

  1. Create a user profile in /etc/dconf/profile/user:

    user-db:user
    system-db:local
  2. As root, create a local database for system-wide settings in /etc/dconf/db/local.d/00-screensaver:

    [org/gnome/desktop/session]
    # Set the lock time out to 180 seconds before the session is considered idle.
    idle-delay=180
    [org/gnome/desktop/screensaver]
    # Set this to true to lock the screen when the screensaver activates
    lock-enabled=true
    # Set the lock timeout to 180 seconds after the screensaver has been activated
    lock-delay=180
  3. Override the user's setting and prevent the user from changing it in the /etc/dconf/db/local.d/locks/screensaver file:

    # Lock desktop screensaver settings
    /org/gnome/desktop/session/idle-delay
    /org/gnome/desktop/screensaver/lock-enabled
    /org/gnome/desktop/screensaver/lock-delay
  4. Run dconf update.

GSettings keys

The following GSettings keys are of interest:

org.gnome.desktop.session.idle-delay

The number of seconds before the session is considered idle.

org.gnome.desktop.screensaver.lock-delay

The number of seconds after screensaver activation before locking the screen.

org.gnome.desktop.screensaver.lock-enabled

Set to true to lock the screen when the screensaver goes active.