Prevent suspend when lid close in Fedora 37

For anyone still looking for info on how to configure such a setup I believe there’s a better approach than masking the targets of logind. You can use the HandleX directives in the logind.conf file to achieve the desired effect for each state.

In case you already used the masking solution, you first need to revert the action by unmasking the targets. Try running:

sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

Then, check the sleep.target to verify it’s active

systemctl status sleep.target

Go ahead and then open the logind.conf file:

sudo nano /etc/systemd/logind.conf

Then find the following directives and set them to the values given below (or any other combination you may want):

HandleLidSwitch=suspend
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

Restart the service:

sudo systemctl restart systemd-logind

You will be thrown out of your session so make sure you don’t have any unsaved work.

Enjoy.

NOTE:

OP is missing the HandleLidSwitchExternalPower directive.