{"id":10069,"date":"2020-05-14T16:51:36","date_gmt":"2020-05-14T16:51:36","guid":{"rendered":"http:\/\/ubuntuhandbook.org\/?p=10069"},"modified":"2025-01-18T06:37:52","modified_gmt":"2025-01-18T06:37:52","slug":"lid-close-behavior-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2020\/05\/lid-close-behavior-ubuntu-20-04\/","title":{"rendered":"Change Lid Close Behavior in Ubuntu 24.04 | 22.04 | 20.04"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/ubuntu-laptop-icon.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-45792\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/ubuntu-laptop-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/ubuntu-laptop-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/ubuntu-laptop-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/ubuntu-laptop-icon-700x700.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/ubuntu-laptop-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/ubuntu-laptop-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>This simple tutorial shows how to change the action (e.g., <b>power off<\/b>, <b>hibernate<\/b>, <b>do nothing<\/b>, or <b>lock<\/b>) <b>when laptop lid is closed<\/b> in Ubuntu 20.04, Ubuntu 22.04, and Ubuntu 24.04, while it suspends Ubuntu by default.<\/p>\n<p>NOTE: This tutorial is also tested and works in <b>Ubuntu 22.04<\/b>, and <b>Ubuntu 24.04<\/b> with default GNOME desktop environment. It should also works in other Linux uses systemd.<\/p>\n<p><u>Dconf editor<\/u> offers options to change the action to take when the laptop lid is closed on AC or power, but it doesn&#8217;t work!<\/p>\n<h3>Option 1: Edit logind.conf file<\/h3>\n<p>So far as I know, you can edit the <code>logind.conf<\/code> file to change the lid close action. And it should work on all <u>Ubuntu desktop, server, and flavors<\/u>.<\/p>\n<p><b>1.)<\/b> First, press Ctrl+Alt+T on keyboard to open up a terminal window. When it opens, run command to edit the config file:<\/p>\n<pre style=\"border: none;\">sudo gedit \/etc\/systemd\/logind.conf<\/pre>\n<p>Depends on your Ubuntu edition and desktop environment, replace <code>gedit<\/code> in command with <code>gnome-text-editor<\/code> for Ubuntu 24.04 and higher. Or, use <code>mousepad<\/code> for XFCE, <code>pluma<\/code> for MATE, or <code>nano<\/code> command line text editor that works in most desktops.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-10071\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/edit-logind-600x124.jpg\" alt=\"\" width=\"600\" height=\"124\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/edit-logind-600x124.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/edit-logind-450x93.jpg 450w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/edit-logind.jpg 754w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><b>2.)<\/b> When the file opens, find out the line <b>#HandleLidSwitch=suspend<\/b> and change it to one of following :<\/p>\n<ul>\n<li><b>HandleLidSwitch=lock<\/b> &#8211; lock when lid closed.<\/li>\n<li><b>HandleLidSwitch=ignore<\/b> &#8211; do nothing, some laptops will disconnect Wi-Fi.<\/li>\n<li><b>HandleLidSwitch=poweroff<\/b> &#8211; shutdown.<\/li>\n<li><b>HandleLidSwitch=hibernate<\/b> &#8211; hibernate Ubuntu.<\/li>\n<\/ul>\n<p><i>NOTE: hibernation feature does NOT work out-of-the-box in Ubuntu, you have to <a href=\"https:\/\/ubuntuhandbook.org\/index.php\/2021\/08\/enable-hibernate-ubuntu-21-10\/\" target=\"_blank\" rel=\"noopener\">enabled it first<\/a> if need.<\/i><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10072\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/lidclose-action.png\" alt=\"\" width=\"600\" height=\"365\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/lidclose-action.png 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/lidclose-action-450x274.png 450w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><b>3.) Set lid close action when running on power supply or in docking station<\/b>.<\/p>\n<p>For choice, you may also uncomment &#8216;<code>HandleLidSwitchExternalPower<\/code>&#8216; and\/or <code>HandleLidSwitchDocked<\/code> lines by removing # at their beginning, and change the value to lock, ignore, poweroff, or hibernate.<\/p>\n<p>So the changes will also apply when your laptop is running with power supply, in a docking station, or with external displays.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/externalpower-lidswitch.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-44558\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/externalpower-lidswitch-600x428.webp\" alt=\"\" width=\"600\" height=\"428\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/externalpower-lidswitch-600x428.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/externalpower-lidswitch-300x214.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/externalpower-lidswitch-768x548.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/externalpower-lidswitch.webp 963w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><b>4.)<\/b> After saved the file (for <code>nano<\/code>, press Ctrl+S then Ctrl+X). Finally apply changes by running command to restart systemd-logind service:<\/p>\n<pre>systemctl restart systemd-logind.service<\/pre>\n<p>In current Ubuntu releases, the last command will log user out. <b>But for Ubuntu 22.04 and higher, it&#8217;s better to restart computer instead<\/b>.<\/p>\n<p><b>Note<\/b>: You have to do previous steps every time you want to change the action. And &#8216;<i>Suspend when laptop lid is closed<\/i>&#8216; option in Gnome Tweaks will no longer work before you comment (add <b>#<\/b> at the beginning) the line in \/etc\/systemd\/logind.conf.<\/p>\n<h3>Option 2: Use A Drop-in under \/etc\/systemd\/logind.conf.d<\/h3>\n<p>The first option works good in my case, but it&#8217;s recommended to create &#8220;drop-ins&#8221; in the <code>\/etc\/systemd\/logind.conf.d\/<\/code> directory. So defaults can be easily restored by deleting main file and all drop-ins.<\/p>\n<p>1. First, press Ctrl+Alt+T to open terminal. Then, run command create the directory in case it does not exit:<\/p>\n<pre>sudo mkdir -p \/etc\/systemd\/logind.conf.d<\/pre>\n<p>2. Next, run command to create a &#8216;drop-in'(custom config file), for example <code>lid-close-action.conf<\/code>, under that directory:<\/p>\n<pre>sudo gnome-text-editor \/etc\/systemd\/logind.conf.d\/lid-close-action.conf<\/pre>\n<p>Here also replace <code>gnome-text-editor<\/code> depends on your Ubuntu edition or desktop environment, or use <code>nano<\/code> that works in most cases.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logind-dropin.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47995\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logind-dropin-700x232.webp\" alt=\"\" width=\"610\" height=\"202\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logind-dropin-700x232.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logind-dropin-300x99.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logind-dropin-768x254.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logind-dropin.webp 818w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>3. When file opens, just add following lines and replace <code>ignore<\/code> with one of <code>suspend<\/code>, <code>lock<\/code>, <code>poweroff<\/code>, <code>hibernate<\/code> as you need.<\/p>\n<pre>[Login]\r\nHandleLidSwitch=ignore\r\nHandleLidSwitchExternalPower=ignore\r\nHandleLidSwitchDocked=ignore<\/pre>\n<p>Finally, save file. For <code>nano<\/code> command line text editor, press Ctrl+S to save and Ctrl+X to exit. And, restart computer to apply change.<\/p>","protected":false},"excerpt":{"rendered":"<p>This simple tutorial shows how to change the action (e.g., power off, hibernate, do nothing, or lock) when laptop lid is closed in Ubuntu 20.04, Ubuntu 22.04, and Ubuntu 24.04, while it suspends Ubuntu by default. NOTE: This tutorial is also tested and works in Ubuntu 22.04, and Ubuntu 24.04 with default GNOME desktop environment. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[1910],"class_list":["post-10069","post","type-post","status-publish","format-standard","hentry","category-howtos","tag-lid-close-lock"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/10069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=10069"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/10069\/revisions"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=10069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=10069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=10069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}