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.
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 trialApple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or buy now, $9.99
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
- Open the Sharing settings. Choose Apple menu, System Settings, General, then Sharing.
- 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.
- 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.
- 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.
- Install it on the phone. The iPhone app needs iOS 15.0 or later. Sign in to the same account on both devices.
- Connect by name. MagicDNS gives each device a name, so an SSH app on the phone can connect to
username@your-mac-nameinstead of an IP address. - 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.
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.
- Install tmux on the Mac, for example with
brew install tmux(the tmux install page lists Homebrew and MacPorts). - Start or rejoin a named session with
tmux new -A -s agent, then start your agent inside it. - Detach on purpose with Ctrl-b then d, or just lose the connection. The agent keeps running.
- Reattach from the phone or any computer with
tmux attach -t agent.
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
- Start the agent in tmux and check that Remote Login and Tailscale work with the lid open.
- 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. - Disconnect external displays. With a display connected Clamshell pauses instead of arming.
- 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 trialBattery and heat
- Plug in for long sessions. Clamshell works on battery, and its optional Disarm on low battery setting (off by default) lets the Mac sleep below a level you choose. When that happens your SSH session ends. See running lid-closed on battery.
- Turn the closed screen fully off if agents do not need it. Turning off Clamshell's Let agents use the screen while the lid is closed setting sleeps the display with the lid closed, which uses less battery and keeps the Mac cooler. A terminal agent over SSH does not need the screen.
- Give it air. Apple's guidance is a stable surface with good ventilation, not a bed, pillow or bedding, at 10 to 35 °C (50 to 95 °F). A closed bag fails that test.
- The thermal cutoff ends the session. At serious or critical macOS thermal pressure Clamshell disarms toward normal lid sleep, so the Mac sleeps and SSH stops. Fix the placement rather than rely on the cutoff.
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
- Use a MacBook as a home server with the lid closed
- Use Codex from your phone with the MacBook lid closed
- Claude Code Remote Control with the MacBook lid closed
- Run AI coding agents overnight on a MacBook
- What pmset disablesleep does, and its risks
- Keep a MacBook awake with the lid closed on battery
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.