PAM Script to Turn off auto screen-lock in Gnome Shell

I’ve created a new version of this script that can be run by NetworkManager, turning Gnome screensaver auto-lock on or off as the wireless essid changes.

In Linux, we have Pluggable Authentication Modules and various applications use PAM to authenticate users. Marco Ditri posted about using PAM to run a script that would prevent xscreensaver from locking the screen on his laptop when connected to his home wireless network.

I wanted to do the same in Gnome, so I’ve modified Marco’s script to use gsettings to disable Gnome Shell auto screen-lock when authenticated to particular wireless networks and enable it everywhere else. You’ll find comments in the script on how to incorporate it in your local PAM configuration.

#!/bin/sh -e

# Turn off gnome auto screen-lock when connected to specific wireless networks

# Add the following to /etc/pam.d/gdm-password, just after in the auth block:
#   auth optional quiet /usr/local/sbin/pam_auth_inhibit_lock

# Hat tip - md,


# return the ESSID of this interface
current_essid() {
  /sbin/iwconfig $1 | sed -nre '/ESSID/s/.*ESSID:"([^"]+)".*/\1/p'

# automatically unlock only for these users
case "$PAM_USER" in
  "")         echo "This program must be run by!"
              exit 1

  $AUTH_USER) ;;

  *)          exit 1


# automatically turn off auto screen-lock when connected to these networks,
# otherwise turn on auto screen-lock
case "$CURRENT_ESSID" in
    su -c "DISPLAY=:0 gsettings set org.gnome.desktop.screensaver lock-enabled false" $AUTH_USER
    exit 1
    su -c "DISPLAY=:0 gsettings set org.gnome.desktop.screensaver lock-enabled true" $AUTH_USER
    exit 1

exit 6