Prevent Ubuntu from turning off the screen or suspending when you close the laptop

Nguyễn Quang Minh

1 min read
142 views

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)

  1. Open Terminal:

    sudo nano /etc/systemd/logind.conf
    
  2. Find and edit these lines (uncomment if commented):

    HandleLidSwitch=ignore
    HandleLidSwitchDocked=ignore
    
  3. Save and exit (Ctrl + O, then Enter, then Ctrl + X)

  4. 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)

  1. Install if not already:

    sudo apt install dconf-editor
    
  2. Run:

    dconf-editor
    
  3. Navigate to:

    /org/gnome/settings-daemon/plugins/power/
    
  4. Find and set:

    • lid-close-ac-action'nothing'

    • lid-close-battery-action'nothing'

  5. 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.

1.2K followers
Ôn tập là dễ

Ôn tập là dễ

Nền tảng thi trắc nghiệm số 1 Việt Nam giúp bạn tạo, quản lý và chia sẻ bộ đề một cách nhanh chóng và dễ dàng.

© 2025 Ôn tập là dễ. Tất cả các quyền được bảo lưu.

    🔥 Mua sắm ngay trên Shopee!
    Giúp mình duy trì trang web! 🎉