I have recently switched to Gnome 3 from Gnome 2 (and switched to Linux recently before that), and Gnome 3 doesn't give me as many options to change settings via the GUI, and especially not to change default settings.

Specifically, I'm trying to change the lid close action on my laptop, since I don't want it to suspend on lid close ever. (I changed this for my own user(s) via the gnome-tweak-tool.)

I've taken a few unsuccessful stabs. I imagine this has to do with sudo for some user, whether sudo for root or gdm.

I've tried (in a console window in a Gnome session and in an SSH session from a remote machine):

> sudo gsettings get org.gnome.settings-daemon.plugins.power lid-close-ac-action
> sudo gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action "blank"

For this, I receive an error about an inability to initialize X11.

I've also tried:

> sudo -u gdm gsettings get org.gnome.settings-daemon.plugins.power lid-close-ac-action

But, this asks for gdm's password, which I've never set. I have continued with passwd, but it tells me: Cannot unlock the password for `gdm'! And, I could try forcing an unlock of the user, but this resistance to me indicates that perhaps I should abandon this path.

I don't know if each of these warrants its own line of questioning, but in the end, I'm just trying to set the laptop lid close setting (the default for all users), though I'd like to know more generally how to set Gnome's default preferences.

4 Answers 4


Run sudo su gdm -c 'gsettings …' (or sudo sudo -u gdm gsettings …). The command sudo -u gdm prompts you for a password because you don't have a specific authorization to run commands as gdm through sudo. But root can usurp any user, and you can become root, so first become root then become gdm.

Note that I don't know if running gsettings as the gdm user will set the power management preference for the login screen. Another possibility to try would be to run a command from a script in /etc/gdm/Init/ (or wherever your distribution keeps Gdm's configuration files).

  • +1 for the suggestions regarding the gdm user
    – palswim
    Jan 31, 2012 at 20:26


Thanks to a combination of the answers here, a discussion about setting the login screen's wallpaper, and a general discussion about running an X program from another console, I finally managed to solve this.

I do need to set the setting as the gdm user. But, simply running gsettings set ... as gdm will fail because of the X11 error. So, I also need to attach the command to an X session.

But, sudo su gdm didn't give me the terminal as gdm, as I had hoped, so I eventually created a simple shell script to run the commands I need.



export DISPLAY=":0"
export XAUTHORITY="$1"
export XAUTHLOCALHOSTNAME="localhost"

gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action "blank"

or, more generally (gset.sh):


export DISPLAY=":0"
export XAUTHORITY="$1"
export XAUTHLOCALHOSTNAME="localhost"

gsettings set $2 $3 $4

Once I had this, I could call it like:

sudo sudo -u gdm gset.sh Xauthority-file org.gnome.settings-daemon.plugins.power lid-close-ac-action "blank"

And this does the trick!

One additional note about the Xauthority file: You will need to copy the Xauthority file for your user to a file that gdm has permission to read. (For a quick and dirty example: cp $XAUTHORITY /tmp/.Xauthority and chown gdm:root /tmp/.Xauthority)

  • I tried this after a new install of OpenSUSE 12.3, and could not figure out why I couldn't disable the sleep setting. It turns out, for the login screen, there is a different setting. In /etc/systemd/logind.conf, (uncomment and) set the HandleLidSwitch setting to ignore.
    – palswim
    Oct 25, 2013 at 22:37

You're not supposed to login as gdm user, that's just a convenient way for the OS to assign ownership of a group of files and their associated read,write,execute permissions.

Are you logged in a console or xsession while trying

gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action 'blank'

I logged in as joeuser, did a sudo su - and then

gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action 'blank'

And received no errors

Or, as root, you can also edit the XML schema file that is the default for all users

sudo vi /usr/share/glib-2.0/schemas/org.gnome.settings-daemon.plugins.power.gschema.xml

search for the 'lid-close-ac-action' key and change the <default> value

  • I've updated the question, but I'm running in a Gnome Shell session using the Gnome terminal application.
    – palswim
    Dec 24, 2011 at 6:43

I just discovered that I can accomplish this with the dbus-launch command as well, instead of trying to find an X session to which to attach.

I can update Gnome settings for root/gdm/whoever else with the following pattern:

sudo sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action "blank"

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.