# Use Xcode from Linux with SSH and a Rented Mac

Canonical: https://figment.so/blog/mac-xcode-linux-ssh-workflow

SSH from Linux to the rented Mac, run xcodebuild there, and pipe the output into your local tools. ControlMaster, shell aliases, SSHFS and tmux make it feel like a local build.

**If your daily driver is Linux and you need to add an iOS target, SSH to a rented Mac, run `xcodebuild` there, and pipe the output back to your own terminal.** Your editor, shell and scripts stay where they are. The SSH config, aliases and session-keeping script below make that feel native.

## Why do I need a Mac at all?

Linux has no substitute for Apple's SDKs. A Mac host is required for:

- **Platform SDKs.** iOS, watchOS, tvOS and (on Apple silicon) visionOS targets of [Xcode](https://developer.apple.com/documentation/xcode).
- **iOS Simulator.** A macOS process backed by CoreSimulator, not a cross-platform emulator.
- **codesign and notarytool.** Both depend on the macOS Security framework and Apple's notary service.

The useful shape for a Linux developer is to keep the project on Linux, reach the Mac only when the iOS lane runs, and treat it as an appliance for build, test and sign.

## How do I keep SSH fast with ControlMaster?

Each fresh `xcodebuild` over SSH pays a TCP handshake and a key exchange. ControlMaster opens a master socket once, and later connections reuse it, so repeated commands feel local. Add this to `~/.ssh/config` on Linux:

```
Host figment-mac
    HostName <mac-ip-or-hostname>
    User macuser
    IdentityFile ~/.ssh/id_ed25519
    ControlMaster auto
    ControlPath ~/.ssh/cm-%r@%h:%p
    ControlPersist 600
    ServerAliveInterval 60
    ServerAliveCountMax 5
```

`ControlPersist 600` keeps the master alive for ten minutes after the last session closes. Verify:

```bash
# First call opens the master socket
ssh figment-mac 'echo master socket open'

# Second call reuses the socket; should return almost immediately
ssh figment-mac 'xcodebuild -version'
```

To open the master explicitly before a long script and let later `ssh figment-mac` calls share it, use the same ControlPath as the config:

```bash
ssh -fN -M figment-mac
# Close when done:
ssh -O exit figment-mac
```

## How do I make xcodebuild feel like make or cargo?

Define four per-project variables once, then use aliases that read like `make` and `cargo`:

```bash
# Project configuration
export FIGMENT_HOST="figment-mac"
export FIGMENT_PROJECT_DIR="~/MyApp"
export FIGMENT_SCHEME="MyApp"           # replace with your scheme
export FIGMENT_SIM="platform=iOS Simulator,name=iPhone 16"

# Build
alias ios-build='ssh "$FIGMENT_HOST" \
  "set -euo pipefail; cd $FIGMENT_PROJECT_DIR && \
   xcodebuild -scheme \"$FIGMENT_SCHEME\" \
   -destination \"$FIGMENT_SIM\" \
   -configuration Debug build 2>&1"'

# Test
alias ios-test='ssh "$FIGMENT_HOST" \
  "set -euo pipefail; cd $FIGMENT_PROJECT_DIR && \
   xcodebuild -scheme \"$FIGMENT_SCHEME\" \
   -destination \"$FIGMENT_SIM\" \
   test 2>&1"'

# Clean
alias ios-clean='ssh "$FIGMENT_HOST" \
  "set -e; cd $FIGMENT_PROJECT_DIR && xcodebuild clean"'

# Live simulator log, filtered locally
alias ios-log='ssh "$FIGMENT_HOST" \
  "xcrun simctl spawn booted log stream --level debug" 2>&1 | \
  rg --line-buffered "$FIGMENT_SCHEME"'
```

`set -euo pipefail` makes the remote shell exit non-zero on any failure, and SSH passes that exit code back to your terminal, so a wrapping CI job sees a real pass or fail. These are untested examples for your own project, so substitute your scheme and simulator.

## How do I use xcodebuild output with my local tools?

Each alias writes to local stdout, so you can pipe it through anything on your Linux box:

```bash
# Errors and warnings only
ios-build | rg "error:|warning:"

# Full log and a tail at the same time
ios-build | tee ~/build.log | tail -40

# Count failed test cases
ios-test | rg "Test Case.*failed" | wc -l
```

To edit sources in your local Neovim or VS Code, mount the project with SSHFS. It reuses the active ControlMaster socket, so file operations do not pay a new handshake:

```bash
# Debian/Ubuntu: apt install sshfs
mkdir -p ~/mnt/figment-mac
sshfs macuser@figment-mac:/Users/macuser/MyApp ~/mnt/figment-mac

nvim ~/mnt/figment-mac/Sources/ContentView.swift

fusermount -u ~/mnt/figment-mac
```

## How do I keep builds running when my connection drops?

Run them inside tmux on the Mac. Long builds and interactive lldb sessions should outlive your network. Start a named session and reconnect to it:

```bash
# Create if missing; harmless to run repeatedly
ssh figment-mac 'tmux new-session -d -s ios-build || true'

# Attach interactively
ssh -t figment-mac 'tmux attach-session -t ios-build'
```

Here is an auto-reconnect wrapper for your Linux profile:

```bash
mac_shell() {
  while true; do
    ssh -t figment-mac \
      'tmux attach-session -t ios-build 2>/dev/null || tmux new-session -s ios-build'
    local code=$?
    [[ $code -eq 0 ]] && break
    echo "Connection lost (exit $code). Retrying in 5s..." >&2
    sleep 5
  done
}
```

A clean detach (`Ctrl-b d`) returns zero and exits. A dropped link returns non-zero, and the loop reconnects.

## Which Figment Mac plan fits a Linux workflow?

Every Figment plan includes SSH, so this workflow runs on all three. For an iOS lane on Xcode 26.3 or earlier, the [Intel Mac VM](/mac-hosting#intel-vm) ($25 a month, $2 a day) runs macOS Sequoia. Apple's porting guide is explicit that [Intel Macs must use Xcode 26 or an earlier release](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon). Xcode 26.4 and later, Xcode 27, arm64-only tools and visionOS need an Apple silicon plan, such as the [Apple Silicon Mac VM](/mac-hosting#apple-silicon-vm) ($39 a month, $6 a day). For heavy GUI or Simulator work, which we have not measured inside a VM, try the [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro) ($349 a month, cancel any time) and test in the first days. Confirm the exact Xcode and macOS pair in the [Xcode release notes](https://developer.apple.com/documentation/xcode-release-notes). See all [Mac hosting plans](/mac-hosting).

---

**Related guides:**
- [Debug iOS Apps Remotely with LLDB on a Rented Mac](/blog/mac-lldb-remote-debug-xcode)
- [Run iOS Simulator Over SSH on a Remote Mac](/blog/mac-ios-simulator-ssh-remote)
- [Set Up a GitHub Actions Self-Hosted Runner on a Mac](/blog/mac-github-actions-self-hosted-runner)
