转自 How to Make Your Ubuntu 21.10 PC Never Go to Sleep - FOSTips
How to Keep Ubuntu Notebook from Sleeping Even When Lid Closed:
For notebook users, Ubuntu will go to sleep when the lid is closed even you disabled automatic suspend in Settings.
To ignore the lid close action, press Ctrl+Alt+T on keyboard to open a terminal window and run command to edit the configuration file:
sudo gedit /etc/systemd/logind.conf
When the file opens, remove “#” at the beginning of the line: “#HandleLidSwitch=suspend”. And change the value to “ignore”, so the line will be: HandleLidSwitch=ignore.
Save the file and it will take effect in next boot. Or run systemctl restart systemd-logind.service
command to restart the service, though it logged me out and refused to login again in my case!
NOTE: For choice, you may set "HandleLidSwitchExternalPower=ignore" for the behavior when on AC power, or use "HandleLidSwitchDocked=ignore" if more than one display is connected. And use 'lock' to lock screen when lid close may be a good choice.
That’s all. Enjoy!