{"id":10069,"date":"2020-05-14T16:51:36","date_gmt":"2020-05-14T16:51:36","guid":{"rendered":"http:\/\/ubuntuhandbook.org\/?p=10069"},"modified":"2026-05-29T14:38:22","modified_gmt":"2026-05-29T14:38:22","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 26.04, 24.04, or 22.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, Ubuntu 24.04, and Ubuntu 26.04, while it by default suspends your laptop.<\/p>\n<p>NOTE: This tutorial is tested and works in all supported Ubuntu releases 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>As 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 <code>Ctrl+Alt+T<\/code> 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 gnome-text-editor \/etc\/systemd\/logind.conf<\/pre>\n<p>Depends on your Ubuntu edition and desktop environment, replace <code>gnome-text-editor<\/code> in command with <code>gedit<\/code> for Ubuntu 22.04 or earlier. 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><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, power off laptop<\/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-large wp-image-51307\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logindconf-2604-700x385.webp\" alt=\"\" width=\"610\" height=\"336\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logindconf-2604-700x385.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logindconf-2604-300x165.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logindconf-2604-768x422.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logindconf-2604.webp 975w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/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 enable (remove # at the beginning) and configure the following two keys accordingly:<\/p>\n<ul>\n<li><code>HandleLidSwitchExternalPower<\/code>. Control lid close behavior when on AC power.<\/li>\n<li><code>HandleLidSwitchDocked<\/code>. Tell what to do when your laptop is in a physical docking station, or connect with 2 or more external displays.<\/li>\n<\/ul>\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>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><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51308\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logindconf-dropin-700x414.webp\" alt=\"\" width=\"610\" height=\"361\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logindconf-dropin-700x414.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logindconf-dropin-300x178.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logindconf-dropin-768x455.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2020\/05\/logindconf-dropin.webp 887w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\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, Ubuntu 24.04, and Ubuntu 26.04, while it by default suspends your laptop. NOTE: This tutorial is tested and works in all supported Ubuntu releases with default GNOME desktop [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":45792,"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","has-post-thumbnail","hentry","category-howtos","tag-lid-close-lock"],"_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:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/45792"}],"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}]}}