Short version. Turn on Prevent automatic sleeping when the display is off (desktops: System Settings › Energy; laptops: Battery › Options, where it applies on the power adapter only), let the display switch off, and keep the Mac plugged in. A magic packet can only come from a device on the same local network, and reports on Apple silicon are poor, so don't plan around waking it.
Why a sleeping Mac drops off SSH
Apple describes sleep as a state where the Mac is "turned on but consumes much less power". Nothing answers new SSH connections in that state, so your client waits and then times out. Display sleep is different: the screen can be off for days while the system stays awake and reachable. That is the state you want.
One detail explains the usual symptom. The ttyskeepawake setting, per man pmset, prevents idle sleep while a remote login session is active, and counts a session as inactive once it has been idle longer than the system sleep timer. So the Mac stays up while you type, sleeps some time after you stop, and your next connection fails.
The setting that keeps it reachable
Apple has moved this switch several times. From its Mac User Guide for each version:
| macOS | Mac laptop | Mac desktop |
|---|---|---|
| 27, Tahoe 26, Sequoia 15 | Battery › Options › Prevent automatic sleeping on power adapter when the display is off | Energy › Prevent automatic sleeping when the display is off |
| Sonoma 14 | Battery › Options, same switch | Energy Saver, same switch |
| Ventura 13 | The advanced Displays settings | The advanced Displays settings |
Some options may be missing depending on your Mac. To let the screen go dark, set Turn display off on power adapter when inactive under Lock Screen. Note the laptop wording: the switch only covers time on the power adapter. On battery a MacBook still sleeps.
Check and set it from Terminal
pmset writes the same preferences file as System Settings, which is handy over SSH.
pmset -g sudo pmset -c sleep 0 sudo pmset -c displaysleep 10 pmset -g assertions
pmset -gprints the settings in use: look atsleep(the system sleep timer, in minutes),displaysleepandwomp.-capplies a change to charger (wall) power,-bto battery,-ato all power sources. Changing settings needs root, hencesudo.sleep 0sets the system sleep timer to never.displaysleep 10turns the display off after ten minutes.pmset -g assertionslists what is currently holding the system or display awake.
To undo it, set minutes again: sudo pmset -c sleep 10.
caffeinate, for one job at a time
If the Mac only needs to stay awake while something runs, caffeinate holds a sleep assertion for as long as it lives. From its man page:
-iprevents idle sleep. This is also what plaincaffeinatedoes.-sprevents system sleep, and is valid only on AC power.-dkeeps the display awake, which a remote Mac rarely needs.-t 3600drops the assertion after that many seconds.-w 1234holds it until the process with that ID exits.
caffeinate -s caffeinate -i -t 7200 caffeinate -i make
The last form runs a command and holds the assertion until it finishes. Run the first in a multiplexer pane so it survives your disconnect.
MacBooks: the lid decides
Apple lists closing the display as a way to put a Mac laptop to sleep. The settings above govern idle sleep, and a closed lid is not idle sleep, so don't expect them to hold a closed MacBook awake.
The exception Apple documents is closed-lid use with an external display: after connecting one, "you can close the lid and continue to use it with connected accessories", and its display troubleshooting page says a closed-lid Mac laptop must be connected to power and using an external keyboard and mouse. Without a display, the dependable arrangement is plugged in, lid open, display allowed to turn off.
What Wake-on-LAN can and cannot do
The Wake for network access option sits next to the sleep switch (a pop-up menu on laptops, a toggle on desktops). man pmset calls the same setting womp, "wake on ethernet magic packet". Apple's description is narrower than the name suggests: the Mac wakes when someone on the network accesses its shared resources, such as a shared printer or Music playlist, and the feature needs an Apple wireless device that supports 802.11n, meaning an AirPort base station. The mechanism is generally known as Bonjour Sleep Proxy. Apple's current page doesn't use that name and doesn't say an incoming SSH connection will wake anything.
A magic packet is a frame, usually sent as a broadcast, that repeats the target's MAC address sixteen times. Broadcasts are generally not routed, which is why it works inside one local network and not across the internet. Tailscale can't deliver it either: the sleeping Mac is off the tailnet until it wakes.
The workaround is a second, always-on device on the same LAN, such as a Raspberry Pi or NAS you can reach over Tailscale. SSH into it and send the packet from there:
sudo apt install wakeonlan wakeonlan a1:b2:c3:d4:e5:f6
Use the MAC address of the Mac's Ethernet port. Now the limits. Most Wi-Fi interfaces drop their link in low-power states and cannot receive a magic packet, so plan on Ethernet. It wakes a sleeping Mac, not one that is shut down. And user reports for Apple silicon are poor: in a TidBITS Talk thread from spring 2026, the owner of an M1 Mac mini with womp enabled found a packet sent from the same subnet did nothing, and another poster's advice was to never let the Mac sleep. Test at home before you rely on it.
Two smaller notes. Power Nap does not make a Mac reachable: Apple describes it as checking mail, calendar and iCloud during sleep, its macOS 26 guide says the option is only available on Intel-based Macs, and the macOS 27 sleep settings page no longer lists it. And if you only need the Mac at known hours, sudo pmset repeat wake MTWRF 08:00:00 schedules a wake at 8:00 on weekdays.
Recommended setup
Desktop Mac (mini, Studio, iMac). Turn on Prevent automatic sleeping when the display is off and let the display sleep. In the same Energy pane, enable start-up after a power failure if your Mac offers it. Leave Wake for network access on, but treat it as a bonus.
MacBook. Keep it on the power adapter with the lid open, turn on the Battery › Options switch, and let the display turn off. Battery settings also offer a charge limit for a laptop that lives on the charger. Away from power, wrap a specific job in caffeinate -i and accept that the battery is the limit.
The energy cost. Apple warns that preventing sleep may increase power consumption, and publishes the numbers: 4 W idle for the M4 Mac mini, which is about 35 kWh over a year of never sleeping. The 2018 Intel Mac mini idles at 19.9 W, about 174 kWh a year. Check Apple's table for your model.
Melta, our phone app for driving coding agents over SSH, cannot wake a sleeping computer either, so the same settings apply. If the Mac is awake and the connection still fails, work through Fix SSH from your phone.
Common questions
How do I wake a Mac remotely? From outside its network, you generally can't. From inside, a magic packet sent by an always-on device may wake it over Ethernet. Preventing sleep is the dependable answer.
Can I wake a Mac mini from sleep remotely? Only through a helper on the same LAN running something like wakeonlan, and it is unreliable on Apple silicon by user reports. At 4 W idle for the M4 model, leaving it awake is simpler.
Can I wake a MacBook remotely with the lid closed? Don't count on it. Apple documents closed-lid use only with power, an external display, and an external keyboard and mouse.
Does macOS sleep break SSH? A session you are typing in holds off idle sleep through ttyskeepawake. An idle one does not, and once the Mac sleeps, new connections time out.
Sources
- Apple: Set sleep and wake settings for your Mac (macOS 27, 26, 15, 14 and 13 versions)
- Apple: Share your Mac resources when it's in sleep
- Apple: Change Battery settings on a Mac laptop and Change Energy settings on a Mac desktop computer
- Apple: Put your Mac to sleep or wake it
- Apple: Connect an external display to MacBook Air and If your external display is dark or low resolution
- Apple: Turn Power Nap on or off on Mac (macOS 26)
- Apple: Schedule your Mac to turn on or off in Terminal
- Apple: Mac mini power consumption and thermal output
- pmset man page and caffeinate man page (online copies; checked against
manon macOS 26.5) - Wikipedia: Wake-on-LAN and Bonjour Sleep Proxy
- Debian man page: wakeonlan
- TidBITS Talk: Wake-on-LAN with Apple silicon (user reports)
- Daniel D. Beck: Waking up a sleeping computer, remotely (a NAS on Tailscale sending the packet)