Disabling Suspend/Sleep Mode on Ubuntu
This post describes how to prevent Ubuntu Server/Desktop from entering Suspend or Sleep mode.
[01] Environment and Situation
- Ubuntu 24.04 Server / Desktop
- While using Ubuntu remotely over SSH, the connection drops and cannot be re-established
- After a period of inactivity, the system transitions into Suspend/Sleep mode, dropping the session
- Some desktop environments require a reboot to recover
[02] Cause
By default, Ubuntu 24.04 has Suspend/Sleep mode enabled.
1
sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target

[03] Solution
Mask the related services so they cannot start.
1
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

[04] Additional Notes
To re-enable these features:
1
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
