You need to configure logind.conf
- this should not disable suspend, it should just to tell it to ignore the lid switch.
This will also override any of your user's power settings, and will work whether you are logged in or not (system-wide). You can configure it via running:
sudo nano /etc/systemd/logind.conf
You should like something like this:
Change HandleLidSwitch=
line to this (with no #
at the beginning - a #
at the beginning of the line means it is a comment and will be ignored and the defaults will be used):
HandleLidSwitch=ignore
Here is a quote from a manual page - note it can take other values like lock
, poweroff
etc.
HandlePowerKey=, HandleSuspendKey=, HandleHibernateKey=,
HandleLidSwitch=
Controls whether logind shall handle the system power and sleep keys and the lid switch to trigger actions such as system power-off or
suspend. Can be one of "ignore", "poweroff", "reboot", "halt",
"kexec", "suspend", "hibernate", "hybrid-sleep" and "lock". If
"ignore", logind will never handle these keys. If "lock", all running
sessions will be screen-locked; otherwise, the specified action will
be taken in the respective event. Only input devices with the
"power-switch" udev tag will be watched for key/lid switch events.
HandlePowerKey=
defaults to "poweroff". HandleSuspendKey=
and
HandleLidSwitch=
defaults to "suspend". HandleHibernateKey=
defaults to
"hibernate".
The manual page for logind is here
Not a solution, but you may use this script as a workaround:
#!/bin/bash
qdbus com.canonical.Unity /com/canonical/Unity/Session com.canonical.Unity.Session.Lock &&
qdbus com.canonical.Unity /com/canonical/Unity/Session com.canonical.Unity.Session.Suspend
This works with stock Ubuntu with Unity desktop. The approach is specific to Unity, although there are dbus
calls to suspend regardless of the desktop environment. For 16.04 , one could use systemctl suspend
command. See the relevant post: https://askubuntu.com/a/1795/295286
Alternative (older answer, edited)
One of the other tools for suspending, that works regardless of the Ubuntu version is pm-suspend
. Problem is that it requires root privilege. To work around that, add pm-suspend to /etc/sudoers
file to be executed without password ( more info here ).
In particular, in my /etc/sudoers
I have the following:
# Allow using pm-suspend for my user without password
serg ALL = NOPASSWD: /usr/sbin/pm-suspend
Thus, you can use:
sh -c 'gnome-screensaver-command -l && sudo pm-suspend'
The sudo pm-suspend
won't prompt you for password then.
Best Answer
In Ubuntu 18.04 Gnome desktop, there’s no option in Settings utility for configuring laptop lid close actions. And Gnome Tweaks only offer a switch to enable/disable ‘Suspend when the laptop lid is closed.
Follow the steps:
sudo gedit /etc/systemd/logind.conf
It will be like the below image:
Save and exit the file.
systemctl restart systemd-logind.service
That's it, This method will fix your issue.