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.