Mouse JigglerMade for MacApp Store
macOS guides

Keep Your Mac Awake for SSH Sessions

Set sleep prevention on the SSH host, the Mac client, or both. Check the request and distinguish a sleeping computer from a failed connection or stopped job.

A brushed silver desktop computer with two glowing glass terminal symbols connected by a blue arc.
Editorial illustration
The quick answer

Set sleep prevention on each Mac that must stay awake. A caffeinate command in an SSH shell runs on the remote host; one in a local Terminal tab runs on your client. SSH keepalive probes check the connection, not either Mac’s power state.

Identify the host and the client first

The host is the Mac you log into. The client is the computer where you type the SSH connection command. Once you log in, commands entered in that remote shell run on the host. A fresh local Terminal tab still runs on the client.

If a MacBook connects to a Mac mini, they have separate power settings. The mini must stay awake to serve the connection; the MacBook must stay awake to keep its client running.

Your goalWhere to set sleep prevention
Reach a Mac later using SSHOn that host Mac, before you leave it.
Keep a local Mac’s SSH window connectedOn the local client Mac; check the host independently.
Run a command on a remote Mac without idle sleepIn the remote Mac’s shell, with the job’s lifetime in mind.

A locked screen, a dark display, and system sleep are different states. You can retain password protection while managing sleep; see our Mac sleep and screen-lock guide.

Check Remote Login while the host is available

If SSH already works, leave its access configuration alone. For a Mac you own or administer that needs initial setup, open System Settings → General → Sharing, open the information panel for Remote Login, and enable it. Choose the specific accounts allowed to connect. Copy the connection command shown in that panel and try it from the client while you can still reach the host locally.

Apple’s Remote Login instructions describe SSH access and account selection. The command has the form ssh username@hostname; use the actual account and address shown for your Mac. Full disk access is a separate permission, not a sleep-prevention switch.

Use an already configured, trusted network route. Enabling Remote Login does not by itself arrange access from another network. If the first connection fails while both Macs are awake, resolve the address, account, or network problem before changing sleep settings.

Give the host a temporary awake window

For a two-hour window, open Terminal locally on the host Mac before leaving it and run:

caffeinate -i -t 7200

Keep that Terminal session open. The command holds an idle-system-sleep request for 7,200 seconds, then releases it. It does not request a continuously lit display. Press Control-C in that window to end it early. The timer starts when you launch the command, not when someone connects.

Started at 13:00, this timer ends around 15:00. Connecting at 14:45 leaves about 15 minutes, not another two hours.

For ongoing access on external power, Apple documents a power-setting alternative: on a MacBook, open Battery → Options and enable the setting that prevents automatic sleep on power when the display is off. On a desktop Mac, look under Energy. Options vary by model. Note the original value so you can restore it.

Use external power and leave a MacBook host’s lid open for this procedure. Neither setup is a promise of availability through a restart, a network outage, or closed-lid operation. Our closed-lid guide covers that separate case.

Protect a command or the client session

Inside an existing remote Mac shell, a command-scoped request can cover one utility. This harmless example waits for thirty seconds:

caffeinate -i /bin/sleep 30

The idle-sleep request ends with the utility. For real work, replace /bin/sleep 30 with the command and arguments you actually intend to run. Apple’s caffeinate manual documents both lifetime modes; a -t timeout is not used when a utility is supplied.

On a local Mac client, you can instead wrap its SSH process:

caffeinate -i ssh username@hostname

Replace the example login with yours. This requests that the client avoid idle sleep while that SSH process runs. It does not install an awake request on the host. See the complete caffeinate guide for other options.

A job attached to a terminal may stop when that window closes or SSH disconnects. If it needs to survive disconnection, use its documented background or resume method, or a persistent session configured separately. Try recovery with a disposable job before relying on it.

Keepalive messages check a different problem

If the Macs remain awake but a quiet SSH connection becomes unresponsive, you can test client-side server-alive probes:

ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=3 username@hostname

After thirty seconds without incoming data, the client requests a response through the encrypted connection. With three unanswered probes, it disconnects after approximately ninety seconds. This example makes failure detection more predictable; it is not a ninety-second session limit when the server continues replying.

OpenSSH documents these controls. They do not reconnect a lost session, repair Wi-Fi, or preserve a remote job. Keep the original error text and time so you can compare a connection failure with what the host was doing.

Verify on the right Mac before leaving

While the host’s timed request is running, use a second Terminal window on that host, or another authenticated shell on it, to run:

pmset -g assertions

Look in the process-owner entries for caffeinate and PreventUserIdleSystemSleep. Record its process ID. A summary value of 1 alone cannot tell you which app owns the request. Our sleep-assertion diagnostic guide shows how to read the owner and check its disappearance afterward.

While you still have local access, connect from the client, let the host display turn off, and run date after the usual idle interval. Record whether it responds. This checks that interval on your setup, not long-term availability.

ObservationNext check
SSH works while the host’s display is darkA lit display was unnecessary for that observed interval.
The client sleeps or changes networkCheck its power and connection separately from the host.
The host is awake but SSH failsCheck Remote Login, the allowed account, address, and network route.
SSH reconnects but the job is goneInspect the job’s output and session-lifetime behavior before restarting it.

Finish the session and check the result

Check the job’s own completion result before disconnecting: its exit status, saved output, or application log, as appropriate. An SSH prompt only proves the shell is responsive. Avoid starting a second copy of an uncertain job until you know whether the first is still running.

End your timed request early with Control-C if it is no longer needed, or allow its timer to expire. Confirm that its process-owner entry disappears; another app may still have an independent request. Restore any temporary power preference. Use exit to leave the remote shell; this ends your session but does not turn off the Mac’s Remote Login service.

Where Mouse Jiggler fits, and what we tested

On a Mac running Mouse Jiggler, Prevent Sleep While Active provides a graphical control to review alongside the session conditions. SSH setup, reconnection, and job recovery remain separate. Leave automatic clicks, scrolling, and key presses off for this command-line task.

On November 2, 2026, we checked a four-second timed request and a four-second command-scoped request on macOS 27.0.1. In both, the caffeinate owner’s idle-sleep assertion appeared and disappeared after completion. We also checked that the local SSH client accepted the two server-alive values without making a connection. These were short local checks, not a two-hour SSH endurance test, a closed-lid test, or a remote job-recovery test. The cover is an editorial illustration.

If you prefer menu-bar controls on a Mac you manage, download Mouse Jiggler on the Mac App Store on that Mac and review its sleep-prevention and stop settings. It does not configure SSH or keep another computer awake remotely.

Need a different timer or a command-scoped session?

Choose the awake request on the correct Mac and confirm it ends when intended. Check SSH connectivity separately.

Choose a caffeinate command

View Mouse Jiggler on the Mac App Store · Free to download, with optional PRO features.