mac-remote
Latest: v1.0.0
mac-remote 1.0.0 establishes approval-first remote management for macOS over SSH.
- Requires explicit approval for every command, including read-only checks, verification, retries, and rollback.
- Documents LAN and reverse-tunnel SSH routes, with aliases kept in
~/.ssh/config. - Adds fast and full health-report procedures, including system status and optional logs, updates, and hardware details.
- Provides guidance for app launches and removal, plus reverse-tunnel setup and diagnosis.
Remote management of a macOS machine
Inspect or administer a macOS host over SSH without installing an agent on it. Every command requires explicit approval before execution. Prefer read-only inspection before proposing changes.
Approval gate
- Show the exact command or complete command batch.
- Identify the target and explain the purpose.
- For state-changing commands, describe the effects and rollback method.
- Wait for the user's explicit approval of those commands.
- Execute only the approved commands.
- If another command is needed, request approval before execution.
This gate covers read-only checks, scripts, application launches, configuration changes, verification, retries, and rollback commands. It also covers local and relay commands used for Mac management. For scripts, show their contents or identify the reviewed script and its exact arguments. Approval covers only the displayed commands and the stated execution. A general task request is not approval for undisclosed commands. Tool permissions do not replace user approval.
About this skill
- Two paths, one host. A LAN alias and a
-awayalias that rides a reverse tunnel through a relay. Both land on the same machine and verify against the same pinned host key. - Prefer the LAN path. Measured for the same report: about 1 s on the LAN, about 7 s through the tunnel.
- One round trip, not twenty. Every probe runs inside a single remote
bash -s. LAN links jitter by tens of milliseconds and the tunnel crosses two oceans twice, so a probe-per-connection design is unusable. - No sudo. The skill has no business escalating, and every probe below runs unprivileged.
- Approval is required for every command. The host belongs to whoever sits at it.
Resolving the target
For desktop automation and VSCodium setup, read Desktop setup. Apply the approval gate to every command in that reference.
Aliases live in ~/.ssh/config, and they are the only place the address is recorded. Never guess a hostname or an address.
ssh -G <alias> | grep -E '^(host|hostname|port|proxyjump) ' # what an alias really resolves to
Set MAC_HOST (or pass the host as the first argument) so the scripts stay address-free:
export MAC_HOST=<alias>
A machine reached two ways usually has two aliases:
| Alias | Route | When |
|---|---|---|
<target> | direct, LAN address | same network |
<target>-away | ProxyJump <relay> → <relay>:127.0.0.1:<port> → mac:22 | any other network |
Never hardcode the address in a script or a skill. A DHCP lease moves; ~/.ssh/config is where that is maintained.
Procedure — the health report
scripts/mac_health.sh # uses $MAC_HOST
scripts/mac_health.sh <alias> # explicit host
scripts/mac_health.sh --full <alias> # + log scan, updates, hardware profile
It reports: identity and OS, uptime, load and swap, disk, top CPU and memory consumers, battery and sleep policy, FileVault / SIP / Gatekeeper / firewall, Time Machine state, and addressing. With --full it adds recent errors, pending updates, and a hardware profile with the serial number and UUID masked.
The fast tier is the default on purpose. log show and softwareupdate -l each cost seconds, and the update check reaches the network.
Read-only command examples
Present the selected commands as a batch for approval before execution:
ssh <alias> 'df -h /; sysctl -n vm.swapusage; tmutil latestbackup'
ssh <alias> 'ps -Ao rss=,pid=,comm= -m | head -5'
ssh <alias> 'log show --last 10m --predicate "process == \"kernel\"" --style compact | tail -20'
Stop and ask
All commands require approval. For these actions, explain the consequences before requesting approval:
| Action | Why it is not automatic |
|---|---|
sudo anything | needs a password the user holds, and is outside this contract |
| kill or restart a process or app | can lose unsaved work |
| write, move, or delete a file | the machine is not yours |
softwareupdate -i, package installs | changes system state |
pmset or machine-wide launchctl changes | affects power and boot behaviour |
| reboot or shutdown | ends the tunnel and any remote session |
If a probe needs root, say so and stop. Do not reach for sudo.
Verify app launches
- Request approval for the launch command.
- After launch, request approval for process and listener checks.
- Confirm the expected process exists.
- For a proxy, confirm the configured port has a listener.
- Ask the user to confirm the visible result.
A successful open -a only confirms that the launch request returned successfully. It does not prove the app stayed running. A listener does not prove upstream connectivity.
Remove apps and old agents
- Request approval to inspect the exact app path and matching processes.
- For an agent, inspect its plist and launchd status after approval.
- Distinguish a loaded agent from a running process.
- Show the exact removal commands and recovery method.
- After approval, unload an obsolete agent before moving its files to Trash.
- Move only the approved paths.
- Request separate approval before emptying all Trash contents.
A launchctl list row with - in the PID column describes a loaded job without a running process. RunAtLoad = false does not mean the job is unloaded. Check both configuration and runtime state.
Moving an app to Trash does not remove its preferences or support data. Emptying Trash permanently removes other trashed items too. Recover trashed files before emptying Trash if rollback is needed.
How the tunnel works
The target dials out; the relay never dials in. A consumer router drops inbound connections, IPv6 included, so the reverse direction is the only one available:
<target>-away ──ssh──> <relay>:22
└─ proxy to 127.0.0.1:<port>
▲
│ reverse forward held by the target
mac ──outbound ssh -N -R 127.0.0.1:<port>:localhost:22────────────────┘
- The listener binds
127.0.0.1only on the relay. Nothing is exposed to the internet. - A system LaunchDaemon can run at the macOS login window after boot. It cannot run at the FileVault pre-boot unlock screen.
- The agent type decides when the tunnel exists. A launchd user agent (macOS) or a systemd user unit (Linux) runs only while that user is logged in. A system LaunchDaemon with
UserNameset starts at boot and survives the login window, at the cost of needing root to install — and root to stop. Pick one per machine: running both makes them fight over the listen port, and the loser retries on a timer. - Verify it:
ssh <relay> 'ss -ltn "sport = :<port>"'. A missing listener means the machine slept, rebooted to a disk-unlock screen, or lost its network.
Health of the tunnel itself
| Symptom | Check | Meaning |
|---|---|---|
-away alias times out after ProxyJump | ssh <relay> 'ss -ltn "sport = :<port>"' | no listener → the target-side agent is down |
Connection closed by UNKNOWN | same | the tunnel died mid-handshake, or the machine slept |
Host key verification failed | read the preceding SSH diagnostic | generic summary, not proof of a changed key |
No ... host key is known | inspect the effective HostKeyAlias and client trust entry | missing trusted key for that name and key type |
REMOTE HOST IDENTIFICATION HAS CHANGED | compare the presented key with an independently verified fingerprint | key mismatch — stop and ask. Never delete the entry to bypass verification |
LAN alias fails but -away works | compare ssh -G <target>, the target's current address, and the SSH diagnostic | possible address, routing, network isolation, or trust problem. A lease change is not established |
Verify a missing or changed host key
- Read the complete SSH diagnostic.
- Inspect the effective host-key name and trust-file settings on the client:
ssh -G <alias> | grep -E '^(hostname|port|proxyjump|hostkeyalias|stricthostkeychecking|userknownhostsfile) '
- Ask the owner to obtain the host-key fingerprint locally on the Mac:
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
- Inspect the matching trust entry on the client:
ssh-keygen -F <host-key-name> -f <known-hosts-file> | ssh-keygen -lf -
Use the effective HostKeyAlias when configured. For other key types, use the corresponding public host-key file.
- If no trusted entry exists, compare the candidate fingerprint with the owner's independently supplied fingerprint.
- Get approval before adding a matching key to the client's trust file.
- If an existing key differs, stop for investigation.
- After trust is established, retry with
StrictHostKeyChecking=yes.
A fingerprint collected only through the unverified connection is not independent evidence. A network move alone does not establish an address change.
After approval of the exact command, restart the target side:
ssh <target> 'launchctl kickstart -k gui/$(id -u)/<label>' # macOS
ssh <target> 'systemctl --user restart <unit>' # Linux
Security model — what a compromised target gets
The tunnel key is only harmless because the relay's authorized_keys line is restricted. Verified by test:
restrict,port-forwarding,permitlisten="127.0.0.1:<port>",permitopen="127.0.0.1:1",command="/bin/false"
| An attacker holding the key gets | Result |
|---|---|
| a shell, pty, or any command as the relay user | no — command="/bin/false" replaces every session command |
-L or -D into the relay's private network | no — permitopen points at a dead port, server answers administratively prohibited |
| other listening ports on the relay | no — permitlisten allows one address and port |
| the one allowed listener, forwarded anywhere | yes — so the -away alias must keep StrictHostKeyChecking=yes |
| connection attempts at the relay | yes — log noise, not access |
Two traps, both measured:
restrictalone does not prevent command execution. It disables forwarding, pty, agent and X11, but a plainssh -T key@host 'cmd'still runs.command=is what closes it.restrict,permitlisten=…alone refuses-R("remote port forwarding failed").port-forwardingmust re-enable it, which re-enables-Las well, which makespermitopenmandatory rather than optional.
A tunnel key avoids the bigger problem: no model keys, no repository tokens, no control channel on the target. The only secret added is worth one loopback port on one host.
Pinning one host key to two paths
Reaching one machine two ways would normally mean two known_hosts entries, and a DHCP lease guarantees one of them rots. HostKeyAlias collapses them onto a single entry:
Host <target>
HostName <lan-address>
HostKeyAlias <target>
User <user>
Host <target>-away
HostName 127.0.0.1
Port <port>
ProxyJump <relay>
HostKeyAlias <target>
StrictHostKeyChecking=yes
Cross-check the relay's host key from both machines before pinning, instead of trusting first contact:
ssh-keygen -F <relay> -f ~/.ssh/known_hosts | ssh-keygen -lf -
Blind spots
- Health reports sample state. They do not continuously detect drift.
- Sleep is invisible. A suspended machine looks identical to a broken tunnel.
log showis not a security audit. Retention and predicates vary by macOS version.fdesetup statusreports policy, not reality. Encrypted-volume state on a locked disk needs root.- Latency is not a fault. Tens of milliseconds of jitter to a LAN peer is often Wi-Fi power save, not a broken link.
Rollback
Tunnel removal affects remote access. Present the applicable rollback commands for approval before execution:
# target: stop and remove the tunnel agent
launchctl bootout gui/$(id -u)/<label> && rm ~/Library/LaunchAgents/<label>.plist
# relay: drop the restricted key
grep -v '<tunnel-key-id>' ~/.ssh/authorized_keys > /tmp/ak
install -m 600 /tmp/ak ~/.ssh/authorized_keys
# workstation: delete the two Host blocks, and the pinned key entry
Keep a timestamped copy of authorized_keys before the first edit. It is the one file where a careless rewrite locks you out of your own server.
