Configure automatic logout

User sessions that have been idle for a specific period of time can be ended automatically. You can set different behaviour based on whether the machine is running from a battery or from mains power by setting the corresponding dconf key, then locking it.

Keep in mind that users can potentially lose unsaved data if an idle session is automatically ended.

Set automatic logout for a mains powered machine

  1. Create the user profile which contains the following lines:

    /etc/dconf/profile/user

    user-db:user
    system-db:local

    local is the name of a dconf database.

  2. Create the directory /etc/dconf/db/local.d/ if it does not already exist.

  3. Create a local database for machine-wide settings in /etc/dconf/db/local.d/00-autologout:

    [org/gnome/settings-daemon/plugins/power]
    # Set the timeout to 900 seconds when on mains power
    sleep-inactive-ac-timeout=900
    # Set action after timeout to be logout when on mains power
    sleep-inactive-ac-type='logout'
  4. Override the user's setting and prevent the user from changing it in /etc/dconf/db/local.d/locks/autologout:

    # Lock automatic logout settings
    /org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-timeout
    /org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-type
  5. Update the system databases:

    # dconf update
  6. Users must log out and back in again before the system-wide settings take effect.

The following GSettings keys are of interest:

org.gnome.settings-daemon.plugins.power.sleep-inactive-ac-timeout

The number of seconds that the computer needs to be inactive before it goes to sleep if it is running from AC power.

org.gnome.settings-daemon.plugins.power.sleep-inactive-ac-type

What should happen when the timeout has passed if the computer is running from AC power.

org.gnome.settings-daemon.plugins.power.sleep-inactive-battery-timeout

The number of seconds that the computer needs to be inactive before it goes to sleep if it is running from battery power.

org.gnome.settings-daemon.plugins.power.sleep-inactive-battery-type

What should happen when the timeout has passed if the computer is running from battery power.

You can run gsettings range on a key for a list of values which you can use. For example:

$ gsettings range org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type
enum
'blank' # blanks the screen
'suspend' # suspends the system
'shutdown' # starts a standard shutdown procedure
'hibernate' # hibernates the system
'interactive' # shows a pop-up query asking the user what to do
'nothing' # does nothing
'logout' # log out from the session