Remote Access to Your Home Mac from Work — AWS EC2 Reverse SSH Tunnel Guide (Hands-on Guide 1)

How to reach your home Mac from a work laptop without router settings or port forwarding. Step by step through an AWS EC2 relay server, an always-on autossh tunnel, and VS Code Remote-SSH — the final setup earned after breaking a server once.

Diagram connecting a home computer (PC1) and a work laptop (PC2) through a reverse SSH tunnel on an AWS relay server

Building a Non-Developer's AI Office Hands-on Guide 1. This lays out, start to finish, the remote tunnel that took an entire day in Part 2 of the series, "Eight AI Staff and a Tunnel All the Way Home," so you can follow along. It's the setup that actually worked after breaking a server once and rebuilding it.

What You'll Build

An environment where you connect from a work laptop to a computer at home and use that computer's terminal, VS Code and AI tools as they are. Since a home router blocks connections coming in from outside, you put a tiny relay server (VPS) in the cloud and have the home computer reach out first to keep a connection open. This is a reverse SSH tunnel.

[PC2 work laptop]─SSH─▶[VPS cloud relay server]◀─ reverse tunnel (always on)─[PC1 · home computer]
       ProxyJump          127.0.0.1:2201                   autossh + launchd
  • PC1: the home computer (a Mac in this guide). Left on 24/7; where the real work happens
  • VPS: the relay server (AWS EC2, Ubuntu 24.04 in this guide). All it needs is a public static address
  • PC2: the laptop you use outside (a work MacBook in this guide)

No port forwarding, router configuration or public IP is needed, because the home side uses only outgoing connections.

What You Need

  • An AWS account (you can start on the free tier) — other VPS providers work the same way
  • Homebrew and autossh on PC1 (brew install autossh)
  • A terminal on all three machines. Copy and paste the commands; replace only the <angle bracket> parts with your own values

Step 1 — Prepare PC1 (Home Computer)

Preparing a home Mac for remote access — turning off macOS automatic updates, enabling Remote Login, disabling sleep with pmset

1-1. Keep It Awake

sudo pmset -a sleep 0 disksleep 0

Use -a (always), not -c (only on power). This is the most common point of failure.

1-2. 🔴 Prevent Overnight Automatic Reboots — Without This, Everything Else Is Pointless

A Mac with disk encryption (FileVault) on stops at the lock screen if an automatic update reboots it overnight. Until someone types the password, neither the tunnel nor SSH comes up. There's no way to fix it from outside.

  • System Settings → General → Software Update → ⓘ next to Automatic Updates → turn off "Install macOS updates" (this is the only item that causes reboots)
# Power back on automatically after an outage
sudo pmset -a autorestart 1

⚠️ Commands like softwareupdate --schedule off did not take effect on recent macOS. Always turn it off in the settings screen above.

1-3. Turn On Remote Login

System Settings → General → Sharing → turn on "Remote Login" → in ⓘ, check that your account is on the allowed list. (Turning it on from the command line was blocked by permission issues.)

# Check — passes if you see a .22 line
netstat -an | grep LISTEN | grep '\.22 '

Step 2 — Create the VPS (Relay Server)

In the AWS console, switch the region to Seoul (ap-northeast-2) (or whichever is closest to you), then EC2 → Launch instance.

ItemValue
AMIUbuntu Server 24.04 LTS (Arm)
Typet4g.nano–small (it only relays, so small is fine)
Key pairUse "Import key pair" and paste PC1's public key (cat ~/.ssh/id_ed25519.pub)
Security groupInbound SSH (22) — 0.0.0.0/0 at first, narrow it once you know your office IP

Once the instance is up, allocate and attach an Elastic IP. Otherwise the address changes whenever you stop and start it. Below, this address is <relay_server_IP>.

Step 3 — Configure the VPS (from PC1's Terminal)

ssh ubuntu@<relay_server_IP>

⚠️ Don't close this window until you're done. Even if a bad setting blocks new connections, the open window survives and lets you roll back.

3-1. A Dedicated Relay Account

sudo adduser --disabled-password --gecos "" relay
sudo mkdir -p /home/relay/.ssh
sudo cp ~/.ssh/authorized_keys /home/relay/.ssh/authorized_keys
sudo chown -R relay:relay /home/relay/.ssh
sudo chmod 700 /home/relay/.ssh && sudo chmod 600 /home/relay/.ssh/authorized_keys

3-2. Auto-Clean Dead Tunnels — Add Only This

sudo tee /etc/ssh/sshd_config.d/99-keepalive.conf >/dev/null <<'EOF'
ClientAliveInterval 30
ClientAliveCountMax 3
TCPKeepAlive yes
EOF

Without this, when the tunnel drops uncleanly the server keeps holding the dead connection, and reconnection keeps failing with remote port forwarding failed. No restart needed.

🔥 An accident that actually happened: don't add a Port line here. The SSH server on Ubuntu 24.04 runs via systemd socket activation, and adding Port to the config causes a port conflict so that SSH dies on the next restart and never comes back. Even the syntax check (sshd -t) doesn't catch it. This accident forced throwing away the first server and building a new one. The remaining values, like disabling password login and allowing forwarding, are already safe in AWS Ubuntu's defaults.

Step 4 — Keep the Reverse Tunnel Running on PC1

4-1. SSH Configuration

ssh-keyscan -H <relay_server_IP> >> ~/.ssh/known_hosts

cat >> ~/.ssh/config <<'EOF'
Host relay
    HostName <relay_server_IP>
    User relay
    IdentityFile ~/.ssh/id_ed25519
    ServerAliveInterval 30
    ServerAliveCountMax 3
    ExitOnForwardFailure yes
EOF
chmod 600 ~/.ssh/config

ssh relay "echo relay server connection OK"

Why register the host key in advance: if a "Do you trust this server?" prompt appears during automatic execution, it gets stuck there.

4-2. Start Automatically at Every Boot (launchd)

cat > ~/Library/LaunchAgents/local.autossh-relay.plist <<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
  <key>Label</key><string>local.autossh-relay</string>
  <key>EnvironmentVariables</key><dict><key>AUTOSSH_GATETIME</key><string>0</string></dict>
  <key>ProgramArguments</key><array>
    <string>/opt/homebrew/bin/autossh</string>
    <string>-M</string><string>0</string><string>-N</string>
    <string>-R</string><string>127.0.0.1:2201:localhost:22</string>
    <string>relay</string>
  </array>
  <key>RunAtLoad</key><true/>
  <key>KeepAlive</key><true/>
  <key>StandardErrorPath</key><string>/tmp/autossh-relay.err.log</string>
</dict></plist>
EOF
launchctl load ~/Library/LaunchAgents/local.autossh-relay.plist
  • -R 127.0.0.1:2201:localhost:22 — attaches PC1's SSH (22) to the relay server's internal-only port 2201. It isn't exposed to the internet
  • AUTOSSH_GATETIME=0 — keeps retrying instead of giving up if the network comes up late right after boot
  • ⚠️ Since it runs in the user session, leave PC1 logged in

Step 5 — Verify Before Leaving Home

# ① Is the tunnel port open on the relay server? → you should see 127.0.0.1:2201
ssh relay "ss -tln | grep 2201"

# ② Round trip — PC1 → relay server → back to PC1
ssh -J relay -p 2201 <PC1_username>@127.0.0.1 "hostname && echo round trip OK"

If ② works, the only variable left outside is the office firewall.

Step 6 — Configure PC2 (Work Laptop)

6-1. Register the Laptop's Key on the Relay Server — No Need to Carry a Private Key Around

# On PC2
ssh-keygen -t ed25519 -C "laptop"     # skip if you already have one
cat ~/.ssh/id_ed25519.pub              # copy this one line

AWS console → EC2 → select the instance → "Connect" → "EC2 Instance Connect" (user ubuntu). When a terminal opens in the browser:

KEY="paste_PC2_public_key_here"
echo "$KEY" | sudo tee -a /home/relay/.ssh/authorized_keys
echo "$KEY" >> ~/.ssh/authorized_keys   # also to the ubuntu account for recovery (see troubleshooting)

6-2. SSH Configuration on PC2

cat >> ~/.ssh/config <<'EOF'
Host relay
    HostName <relay_server_IP>
    User relay
    ServerAliveInterval 30

Host home
    HostName 127.0.0.1
    Port 2201
    User <PC1_username>
    ProxyJump relay
    ControlMaster auto
    ControlPath ~/.ssh/cm-%r@%h:%p
    ControlPersist 10m
EOF
chmod 600 ~/.ssh/config

ssh home

The first connection asks for PC1's account password. Once in, add PC2's public key to PC1's ~/.ssh/authorized_keys and it won't ask again. The three Control… lines let multiple windows share a single connection.

Step 7 — How to Use It (Real-World Examples)

Coding on the Home Computer with VS Code ← Main Use

Install the VS Code extension Remote - SSH → "><" at the bottom left → Connect to Host → home. Only the editor shows on the laptop; files, terminal, extensions and AI tools all run on the home computer. Remote desktop (VNC), which sends the whole screen, turned out in practice to be too slow for coding.

Use tmux for Long-Running Jobs

ssh home
tmux new -s build        # run long commands in here
# work continues on the home computer even if you close the laptop
tmux attach -t build     # reattach

Advanced — Remotely Debugging the In-Car Tablet from the Home Computer

Remotely debugging an Android tablet by connecting a laptop in the car and the home computer through a reverse tunnel

This office went one step further on the same tunnel. Leave the laptop in the car with the Android tablet plugged in over USB, and lend the laptop's adb back to the home computer.

# PC2 (laptop in the car)
adb devices
ssh -R 5038:localhost:5037 home

# PC1 (home) — now the tablet in the car is visible
ADB_SERVER_SOCKET=tcp:localhost:5038 adb devices
ADB_SERVER_SOCKET=tcp:localhost:5038 adb install -r app.apk

Install the app built on the home computer onto the tablet in the car, capture its screen, and pull driving logs. That story comes later in the series.

Troubleshooting

SymptomCause · Fix
ssh relay works but only ssh home times outThe relay server is holding a dead tunnel (remote port forwarding failed). From the laptop: ssh ubuntu@<relay_server_IP> → sudo ss -tlnp | grep 2201 → sudo kill that process. PC1's autossh reconnects on its own — no need to go home
ssh relay itself times out from the officeThe office firewall blocks port 22. Check your company's IT policy first
Home computer doesn't respondIt's asleep (1-1) or logged out (4-2)
Home computer seems completely offUsually stuck at the disk-encryption lock screen after a reboot — can't be recovered remotely. Be sure to do 1-2

Summary

  • Home: stay awake · prevent auto reboots · Remote Login · always-on autossh tunnel
  • Relay server: a dedicated account + three lines to clean up dead connections. Don't touch Port
  • Laptop: one ProxyJump line for ssh home

Without this tunnel, there would be no office where "the home computer works with AI while I'm at the office." The chaos of that first day is in Building a Non-Developer's AI Office Part 2.

※ Check your company's security policy before connecting to an external server from the company network.