Can you SSH into a MacBook with the lid closed?

By Matyas Rathonyi. Updated October 14, 2026. Guides

Yes, but only while the Mac is awake: closing the lid normally sleeps a MacBook, and a sleeping Mac does not answer SSH. Free ways to keep it awake are leaving the lid open on power or Apple's closed-display mode with an external display; Clamshell for Mac keeps it awake and on the network with the lid shut and nothing attached.

Lid closedThe Mac sleeps, SSH stops
Remote LoginBuilt-in SSH server
tmuxSurvives a dropped link
$9.99 onceAfter a 7-day free trial

Clamshell for Mac keeps a closed MacBook awake and on the network while armed, so you can SSH in from your phone and check on your agents. Free for 7 days.

Download free trial

Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or buy now, $9.99

A phone terminal keeps receiving new lines over SSH while the MacBook lid closes. ssh
SSH needs an awake Mac.Remote Login answers only while the Mac is running. Keep it awake with the lid shut and the session keeps scrolling on your phone.

You start Claude Code, Codex or a long build on your MacBook, close the lid, and plan to check on it from your phone. The SSH side is easy: macOS has a built-in SSH server. The hard part is that the MacBook goes to sleep when the lid closes, and nothing answers. This page is the focused SSH answer: turning on Remote Login, why the connection dies at lid close, what Wake for network access does not do, reaching the Mac away from home, and keeping your agent alive in tmux. For Plex, file sharing and a Mac that serves around the clock, see using a MacBook as a home server with the lid closed.

Turn on Remote Login

  1. Open the Sharing settings. Choose Apple menu, System Settings, General, then Sharing.
  2. Turn on Remote Login and click the info button next to it. Under Allow access for, choose Only these users and add only the accounts that need it. There is also an Allow full disk access for remote users switch; leave it off unless your remote work needs it.
  3. Copy the SSH command. Apple's page notes that the exact command is shown below the Remote Login: On indicator. From another computer it looks like ssh username@hostname, where hostname can be an IP address or a domain name.

These steps follow Apple's Remote Login guide, which also warns that allowing remote login can make your Mac less secure. Test the connection with the lid open before you rely on it lid-closed.

Why SSH drops when the lid closes

Closing the display is one of Apple's documented ways to put a Mac laptop to sleep. In sleep the Mac is on but draws much less power, and it stops running your programs, including the SSH server and whatever you started through it. An open session stops responding on the client. New connections fail until someone opens the lid.

Tools that only prevent idle sleep, such as caffeinate, do not change this: lid-close sleep is separate from the idle timer.

Does Wake for network access let you SSH into a sleeping MacBook?

Do not plan around it. On a MacBook the option is in System Settings, Battery, Options. Apple describes it as waking the Mac when a user at another computer accesses its shared resources, with a shared printer or Music playlist as the examples, and at intervals so the Mac can tell the network those resources are available. The same page says the feature needs an Apple wireless device that supports 802.11n with the latest firmware. Apple does not mention SSH, coding agents or a closed lid there. Even where a wake works, a session that depends on the Mac waking on demand is not one you want an agent to depend on.

SSH into the closed Mac from your phone, away from home

At home you can use the Mac's local address. Away from home the Mac sits behind your router, so you need a private network path to it. Tailscale is a common way to get one, and it has a free plan.

  1. Install Tailscale on the Mac. Tailscale supports macOS Monterey 12.0 or later and recommends its standalone download over the Mac App Store and open source variants.
  2. Install it on the phone. The iPhone app needs iOS 15.0 or later. Sign in to the same account on both devices.
  3. Connect by name. MagicDNS gives each device a name, so an SSH app on the phone can connect to username@your-mac-name instead of an IP address.
  4. Keep using Remote Login. Tailscale SSH, its own SSH server, runs on macOS only with the open source tailscaled variant. With the regular Mac app, macOS Remote Login is the SSH server and Tailscale only provides the path.
The phone reaches the Mac through Tailscale, then macOS Remote Login, then a tmux session. Every link needs the Mac awake. Phone Tailscale Mac Remote Login every hop needs the Mac awake
Tailscale finds the Mac, it does not wake it. The phone reaches the Mac's private address from anywhere, and Remote Login answers only while the Mac is running.

Run agents in tmux so a dropped connection does not kill them

Phones switch networks, lock and drop connections. If Claude Code or Codex runs directly in the SSH session, a dropped connection can take the session with it. The tmux documentation lists exactly this use first: protecting programs on a remote machine from connection drops.

  1. Install tmux on the Mac, for example with brew install tmux (the tmux install page lists Homebrew and MacPorts).
  2. Start or rejoin a named session with tmux new -A -s agent, then start your agent inside it.
  3. Detach on purpose with Ctrl-b then d, or just lose the connection. The agent keeps running.
  4. Reattach from the phone or any computer with tmux attach -t agent.
The phone's SSH link breaks, but inside tmux on the awake Mac the agent keeps printing lines. tmux: agent Link drops, Mac awake When the Mac sleeps, tmux cannot help: the session and the agent stop until the Mac wakes. tmux: agent z Mac asleep
tmux protects the session, not the Mac. A dropped link is harmless while the Mac is awake. Once it sleeps, the agent stops too, and you reattach to the same session after it wakes.

Keep the closed Mac reachable

Lid open on power, free

In System Settings, Lock Screen, set Turn display off on power adapter when inactive, and in Battery, Options, turn on Prevent automatic sleeping on power adapter when the display is off, both from Apple's sleep settings guide. The display goes dark and SSH keeps working. The simplest setup if the lid can stay up.

Closed-display mode, free

An external display, keyboard and mouse, plus power, keep a closed MacBook awake, as Apple describes. Good at a desk. It does not help once you unplug and leave.

sudo pmset -a disablesleep 1, free

Works with nothing attached, but it is a global admin switch with no timer, and it stays on across restarts until you turn it off. Forget it and the Mac stays awake in a bag. See what pmset disablesleep does before using it.

Clamshell for Mac, $9.99 once

Keeps an Apple Silicon MacBook on macOS 14 or later awake and on the network with the lid closed while armed, with no external display, sudo or admin password. Normal lid sleep returns when you disarm or quit, and arming is never saved across a restart.

SSH with Clamshell armed

  1. Start the agent in tmux and check that Remote Login and Tailscale work with the lid open.
  2. Arm so it stays armed. Arm from the right-click menu or the Shortcuts Arm action: those stay active across lid openings until you disarm. Arming from the regular menu covers the next close only. From a terminal on the Mac, open "clamshell://arm" also arms it; the request is asynchronous, so check the menu bar before you close the lid.
  3. Disconnect external displays. With a display connected Clamshell pauses instead of arming.
  4. Close the lid and test from the phone. The built-in display stays black and the Mac stays on the network, so SSH keeps answering. Opening the lid locks the Mac.

Know the limits. Clamshell does not watch your agent or your SSH sessions, and it does not reconnect Wi-Fi. If you restart the Mac over SSH, Clamshell is not armed after the restart, so the next lid close sleeps the Mac as usual. More on running agents unattended in running AI agents overnight on a MacBook.

Clamshell keeps your Mac awake with the lid closed. Free for 7 days, then $9.99 once for one Mac. 14-day money-back guarantee.

Download free trial

Battery and heat

Frequently asked questions

Can I SSH into my MacBook with the lid closed?

Yes, as long as the Mac is awake. Closing the lid normally puts a MacBook to sleep, and a sleeping Mac does not answer SSH. Keep it awake with the lid open on power, Apple's closed-display mode with an external display, or Clamshell for Mac with nothing attached.

Does Wake for network access let me SSH into a sleeping MacBook?

Do not count on it. Apple describes it as waking the Mac when another computer accesses shared resources such as a shared printer or Music playlist, and says it needs an Apple 802.11n wireless device with current firmware. Apple's page does not mention SSH or a closed lid.

How do I SSH into my Mac from my phone when I am away from home?

Install Tailscale on the Mac and the phone and sign in to the same account, then use an SSH app on the phone to connect to the Mac's Tailscale name with Remote Login turned on. The Mac still has to be awake.

Will my agent keep running if the SSH connection drops?

Only if it runs inside tmux or a similar tool. tmux keeps the session and its programs running after the connection drops, and you reattach with tmux attach. tmux does not keep the Mac awake, so it cannot help once the Mac sleeps.

Is sudo pmset disablesleep 1 a good way to keep SSH working with the lid closed?

It works with nothing attached, but it is a global admin setting with no timer that stays on until you turn it off, even across restarts. If you forget it, the Mac stays awake in a bag. Clamshell keeps the lid awake only while armed and needs no admin rights.

Related guides

Sources checked October 14, 2026: Apple's guides on Remote Login, putting a Mac to sleep, sharing resources during sleep, sleep and wake settings, closed-display mode and laptop operating temperatures; Tailscale's macOS and iOS install guides, MagicDNS, Tailscale SSH and pricing pages; and the tmux wiki. Clamshell behavior is described from its changelog and FAQ. Clamshell is an independent app, not affiliated with or endorsed by Apple or Tailscale. Tailscale is a trademark of its owner.