Surely many of you have faced the fact that when you close the lid of the laptop, your Ubuntu does not go to sleep mode but continues to work or the screen turns off but Ubuntu continues to run. This is somewhat annoying or ineffective since the correct thing to do would be to go to sleep and save energy, either from the laptop battery or from the electrical network.
There a bug that prevents entering this mode when we close the laptop lid, a bug that has not yet been solved but can be corrected with tricks. In this case we are going to tell you a trick that will allow you to suspend the equipment when you close the laptop lid.
Ubuntu does not usually go to sleep when we close the laptop lid
First of all we have to make sure that in the Energy configuration we must have the option of «Suspension» in the section on closing the laptop lid. Still it will not work due to the mentioned bug. That is why after maintaining this configuration, we have to open the terminal and write the following:
sudo apt-get install pm-utils
After installation we will write the following:
sudo nano /etc/systemd/logind.conf
This will show us a file with several commented lines. The trick is to uncomment certain lines so that the pm-utils program works in an extraordinary way and send the computer to sleep by closing the laptop lid. So we have to uncomment the following lines:
HandleSuspendKey=suspend HandleLidSwitch=suspend HandleLidSwitchDocked=suspend
We save all the changes and restart the system. Now when we close the lid of the laptop the equipment will go into suspension with the consequent energy saving. This trick is valid with the latest versions of Ubuntu although with Ubuntu 18.04 it has not been tested. In any case, the energy savings will be considerable and the efficiency of the operating system.