SSH into a remote Mac: a step-by-step guide from login and config to Xcode commands

 ·  About 14 minutes  ·  Tutorial

A terminal session that logs in, keeps a config, and finishes one xcodebuild

The panel already shows an address and a password, and the first ssh still never reaches a shell—or it does, and Xcode is not there. What follows is one session in order: get in once, write a config you can reuse, prove the toolchain, run a single build, then deal with the keychain. The flag that belongs to a step stays in that step.

The address 203.0.113.10 is a documentation range, and builder is a placeholder. Substitute your host. This page ends when one build command finishes on the remote Mac. Mapping that Mac into an editor, and firing tests from Linux with nobody watching, are two other pages.

3
stages: login, config, build
600
mode of the private key
0
times host-key checks are turned off

What you need before the first login

Three things, and none of them is optional. A host is an address, a port, and a user name. A credential is either a one-time password or a private key that already lives on your laptop. The system is a Mac with Remote Login on, and this user can use the Xcode that is installed—or is allowed to install it.

On macOS the switch is System Settings → General → Sharing → Remote Login. If the allow list says “Only these users,” your account has to be on it. A correct password for someone who is not on the list looks the same as a refused login. A cloud Mac usually ships with Remote Login already on. If the machine is still sitting on the FileVault unlock screen, sshd is not running yet, and a reachable address still times out. Confirm it has passed disk unlock before you debug the client.

Do not make root the everyday account

Use the normal user the provider gave you. DerivedData, simulators, and the login keychain hang off that user. Switching to root makes the signing steps later point at the wrong home.

The first connection

Run this on your own computer. Change -p when the port is not 22.

Your computer · first login
ssh -p 22 builder@203.0.113.10

The first attempt stops on “authenticity of host can’t be established” and prints a fingerprint. Type yes only after the fingerprint matches the one in the provider panel. That writes the host key into ~/.ssh/known_hosts. After a reinstall, the same address has a new fingerprint, and OpenSSH refuses the connection because the host identification changed. Remove the old line with ssh-keygen -R 203.0.113.10, then accept the new fingerprint against the panel. If you were not expecting a reinstall, do not delete the old key and continue.

A password is fine for this one session. After that, a key, or every script will wait at a prompt.

Your computer · key, then install it
ssh-keygen -t ed25519 -f ~/.ssh/id_mac_build -C "build-laptop"
ssh-copy-id -i ~/.ssh/id_mac_build.pub -p 22 builder@203.0.113.10

Current macOS and most Linux installs include ssh-copy-id. The OpenSSH client that ships with Windows often does not. The pipe below does the same job. It is least fussy from Git Bash or WSL, where the quotes match a Unix shell.

When ssh-copy-id is missing
cat ~/.ssh/id_mac_build.pub | ssh -p 22 builder@203.0.113.10 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys'

Wrong modes make sshd ignore the key. The message is about ownership or permissions, not about a bad password. The private key on your computer is 600. The remote ~/.ssh directory is 700. authorized_keys is 600. A directory left at 755 looks like the key was copied, and login still falls back to a password.

This section is done when the next command opens a shell and does not ask for a password:

Your computer · this key only
ssh -i ~/.ssh/id_mac_build -o IdentitiesOnly=yes -p 22 builder@203.0.113.10

IdentitiesOnly stops the client from offering every other key in the agent. After too many tries the server refuses the connection, which looks exactly like a key that was never installed.

One Host alias

Write those flags into a config so later commands stay short. On macOS and Linux the file is ~/.ssh/config. On Windows it is C:\Users\your-name\.ssh\config, and IdentityFile uses a Windows path.

~/.ssh/config
Host cloud-mac
  HostName 203.0.113.10
  User builder
  Port 22
  IdentityFile ~/.ssh/id_mac_build
  IdentitiesOnly yes
  ServerAliveInterval 30
  ServerAliveCountMax 6

Login becomes ssh cloud-mac. A remote command becomes ssh cloud-mac 'xcodebuild -version'. The keepalive only stops a middlebox from dropping an idle session. A build that runs for many minutes still dies when the laptop lid closes. That case is in the failure table, handled with tmux.

Do not put StrictHostKeyChecking no in this file. When a script connects the first time and you have already compared the fingerprint, use accept-new. It trusts the first key it sees and rejects a later change.

Your computer · accept a new fingerprint once
ssh -o StrictHostKeyChecking=accept-new cloud-mac

Multiplexing, an editor’s Remote SSH, and forwarding ports back to the laptop are a different page: map a cloud Mac over SSH so it feels local. The config here only keeps a command channel steady.

Prove this Mac can compile

A shell is not a toolchain. If only the Command Line Tools are installed, the name xcodebuild may exist, and an archive still stops immediately.

Remote · three checks
ssh cloud-mac 'sw_vers'
ssh cloud-mac 'xcodebuild -version'
ssh cloud-mac 'xcode-select -p'

You want a macOS version, a line such as Xcode 16.x, and the path /Applications/Xcode.app/Contents/Developer. A path of /Library/Developer/CommandLineTools means the selector is wrong. Point it back, then print it again.

Remote · selector and first launch
# -t or sudo reports that no terminal is available
ssh -t cloud-mac 'sudo xcode-select -s /Applications/Xcode.app'
ssh -t cloud-mac 'sudo xcodebuild -license accept'
ssh cloud-mac 'xcodebuild -runFirstLaunch'

-runFirstLaunch installs the extra pieces that ship inside Xcode. Xcode.app has to already be in /Applications. It is not an installer. If the app is missing, take it from the Mac App Store or expand the xip from developer.apple.com, then run the three lines. Why that step cannot be skipped on Windows or Linux is in why an iOS app is compiled on macOS.

Command Line Tools are not a small Xcode

xcode-select --install gives you a compiler for C on that Mac. There is no iOS SDK and no simulator runtime. If the word xcodebuild is present, read the path from -p before you reinstall the system.

Run one xcodebuild

List the schemes the project actually admits. A personal scheme that was never committed lives in xcuserdata on your laptop. A fresh clone on the remote Mac does not have it.

Remote · inside the project
ssh cloud-mac
cd ~/src/App
xcodebuild -list

When the scheme is missing, open Product → Scheme → Manage Schemes on a Mac that has the project, check Shared, commit xcshareddata/xcschemes, and pull again. Do not hand-write a scheme file over SSH to make the list look full.

A simulator compile does not need a window server. A generic destination is enough when nobody is sitting at a remote desktop.

Remote · no specific simulator booted
xcodebuild \
  -scheme App \
  -destination 'generic/platform=iOS Simulator' \
  -configuration Debug \
  build

The last line you want is ** BUILD SUCCEEDED **. To pin a simulator that is already installed, change the destination to platform=iOS Simulator,name=iPhone 16. Take the name from xcrun simctl list devices available, not from memory of a device this Xcode does not ship.

generic/platform=iOS is a device destination and it will demand a signature. If you only want to know the project compiles, stay on the simulator destination. A workspace layout (typical with CocoaPods or a shared SPM setup) uses -workspace App.xcworkspace next to -scheme. Do not also pass -project.

Keychain and signing

An SSH session is not the GUI login session. codesign looks at this user’s login keychain. Two failures show up constantly: the certificate was never imported, or it is there but the keychain is locked—or the private key does not allow codesign without a window. That error is errSecInteractionNotAllowed.

A simulator smoke build can turn signing off for a moment, so you can tell “the project does not compile” from “signing is not ready.” An archive you intend to upload cannot use that switch.

Remote · simulator smoke only
xcodebuild -scheme App -destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO build

A device build or an archive needs the certificate in this user’s login keychain. Keep the password in an environment variable, not in the repo. While the command runs, ps on that Mac can see the argument, so use a build user. Do not use your Apple ID password for this.

Remote · unlock, then allow codesign
security unlock-keychain -p "$KEYCHAIN_PASSWORD" ~/Library/Keychains/login.keychain-db
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" ~/Library/Keychains/login.keychain-db
xcodebuild -scheme App -destination 'generic/platform=iOS' -allowProvisioningUpdates DEVELOPMENT_TEAM=ABCDE12345 build

An archive is the same signing story with an output path:

Remote · archive
xcodebuild -scheme App -destination 'generic/platform=iOS' -archivePath "$HOME/build/App.xcarchive" archive

With no distribution certificate, that command stops at signing. It does not stop because SSH is broken. Prove the toolchain with the simulator build, then fix the certificate on its own.

Which line to read when it fails

What you see Look here first
Permission denied (publickey) Key path, IdentitiesOnly, remote authorized_keys at 600, directory at 700, user on the Remote Login allow list
Host key verification failed The machine was reinstalled. After ssh-keygen -R, compare the new fingerprint with the panel
sudo: a terminal is required Add -t to that ssh
requires Xcode, or the selector points at Command Line Tools xcode-select -p, then point it back at Xcode.app
scheme not found Is the shared scheme in xcshareddata in the repo?
errSecInteractionNotAllowed Keychain still locked, or the partition list does not allow codesign
connection drops halfway through the build The lid or a middlebox killed the session. Leave the build in remote tmux

A long build should not depend on the laptop staying awake. Start a session on the Mac, write the log on that disk, and read the tail when you come back.

Your computer · build stays remote
ssh cloud-mac 'tmux new -d -s build "cd ~/src/App && xcodebuild -scheme App -destination \"generic/platform=iOS Simulator\" build > /tmp/build.log 2>&1"'
ssh cloud-mac 'tail -n 40 /tmp/build.log'

tmux here only keeps this one build alive across a disconnect. Using it as the all-day layer is the low-latency page.

Where this page stops

Login, config, and one xcodebuild you can run again are the front half of the path. When the editor should follow the remote filesystem and ports should come back to the laptop, read the low-latency mapping. When tests should run unattended from Linux or Windows, read remote Xcode tests. That page assumes xcodebuild already runs on this Mac. Why the compile cannot leave macOS is in the four compile hosts. Where “a person in front, a machine executing behind” sits in the stack is the Cloud Mac stack architecture.

Decision

You only need a package built from another computer: stop at BUILD SUCCEEDED. You will edit on that Mac all day: finish this config, then add the editor mapping. You need tests at night with nobody there: this page stops when the command runs; the test matrix is the automation guide.

Questions

Do I have to turn password login off? Not for this page. Use the password once to install the public key. IdentitiesOnly then keeps scripts on the key. Leave the password for recovery. Do not make a script depend on it, or an unattended build stops at a prompt.

Is the Windows config the same file? The fields match. The path is C:\Users\your-name\.ssh\config. IdentityFile points at the private key on that Windows machine. The remote side is always the macOS ~/.ssh. Do not chmod a Windows path over there.

Does a simulator build need a GUI first? Compiling for generic/platform=iOS Simulator does not boot a simulator. Tapping the interface needs a remote desktop. That is outside what this SSH command is for.

sudo keeps asking for a password. What then? The first time, ssh -t and type it. If the build user must change the selector often, allow passwordless sudo for xcode-select and xcodebuild only, not for ALL. Once the selector is stable, ordinary builds do not need sudo.

Is this the same thing as Xcode Cloud? No. Xcode Cloud does not hand you a Mac you can log into. This page is you logging into your own macOS and running the commands, with certificates and DerivedData left on that disk.

ZavCloud Developer Infrastructure

Leave this SSH on a macOS that stays awake

The laptop only starts the command. Xcode, the keychain, and DerivedData stay on the remote Mac, so closing the lid does not cut a build in half.

If you edit the interface and plug in a device all day, keep that seat in front of you.

See Mac cloud plans
New Arrival See Mac cloud plans