How to Enable Automatic Shutdown / Hibernate on idle on Ubuntu

Last updated: April 1, 2024

Unlike laptop lid close action, it’s easy to tell Ubuntu to shutdown or hibernate automatically when reached idle timeout.

In all current Ubuntu releases, including Ubuntu 18.04, Ubuntu 20.04, and Ubuntu 21.04 running with the default GNOME desktop, you can enable ‘Automatic Suspend‘ feature in Power Settings easily.

What if you want to power off, hibernate, or even log-out Ubuntu after it reached inactivity timeout? Here’s how to do this in two ways.

Method 1. Run 2 commands to enable Automatic Shutdown / Hibernate:

Firstly open terminal either from system application launcher or by pressing Ctrl+Alt+T on keyboard.

When terminal opens, run command:

  • Enable automatic shutdown for desktop PC or laptop on AC power:
    gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'shutdown'

    For choices, you can change ‘shutdown’ in command to ‘hibernate‘, ‘logout‘, ‘nothing‘, etc.

  • Change the inactivity timeout (in seconds), half an hour for instance:
    gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 1800

For laptops on battery, use following commands instead:

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'shutdown'
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout 1800

Method 2: Change system idle action via Dconf Editor.

For those prefer graphical configuration tool, search for and install ‘Dconf Editor‘ from Ubuntu Software.

Then launch the tool, and go to ‘org/gnome/settings-daemon/plugins/power‘.

Next scroll down, find out and change the values of ‘sleep-inactive-ac-type‘ and ‘sleep-inactive-ac-timeout‘ for system idle action when on AC power.

When on battery, change the values of ‘sleep-inactive-battery-type‘ and ‘sleep-inactive-battery-timeout‘ instead.

Changes will take place immediately when you click on ‘Apply’ button.

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via ubuntuhandbook1@gmail.com Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

2 responses to How to Enable Automatic Shutdown / Hibernate on idle on Ubuntu

  1. Hi Ji m,
    Thank you for your post!
    Unfortunately it seems to have no effect on my Ubuntu 20.04 with vanilla Gnome desktop.
    Any ideas?
    Thanks

    • Make sure there’s no background process prevent your system going idle/suspend/shutdown, and leave System Settings -> Power -> Automatic Suspend unchange afterwards, since it may override the setting via the gsettings command or dconf editor.

      For automatic hibernate you have to make sure the function itself works (save your work and try “sudo pm-hibernate” command).