Prevent Ubuntu from turning off the screen or suspending when you close the laptop
Nguyễn Quang Minh
To prevent Ubuntu from turning off the screen or suspending when you close the laptop lid, follow these steps depending on your desktop environment (GNOME or others):
✅ For Ubuntu GNOME (default Ubuntu Desktop)
Option 1: Use logind.conf
(Works regardless of GUI)
Open Terminal:
sudo nano /etc/systemd/logind.conf
Find and edit these lines (uncomment if commented):
HandleLidSwitch=ignore HandleLidSwitchDocked=ignore
Save and exit (
Ctrl + O
, thenEnter
, thenCtrl + X
)Restart
systemd-logind
to apply changes:sudo systemctl restart systemd-logind
🟡 Note: This disables suspend on lid close system-wide, even if on battery. Be careful.
✅ Option 2: For GNOME Users – Using dconf-editor
(GUI way)
Install if not already:
sudo apt install dconf-editor
Run:
dconf-editor
Navigate to:
/org/gnome/settings-daemon/plugins/power/
Find and set:
lid-close-ac-action
→'nothing'
lid-close-battery-action
→'nothing'
Close the app – settings are saved immediately.
✅ Verify Settings (Optional)
Check current logind settings:
cat /etc/systemd/logind.conf | grep HandleLid
Check current suspend targets:
systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
Nguyễn Quang Minh
Passionate developer and writer sharing insights about technology, programming, and digital innovation. Follow for more content about web development and tech trends.