Last updated: August 25, 2026. Technical details were checked against Apple Developer Documentation, Apple Developer Account Help, and Apple Developer Forums.
Decision: Do not revoke or regenerate a certificate first. Compare the same signing task in a graphical session and over SSH under the same macOS user, then inspect the signing identity, matching private key, Keychain state, and trust chain. Reimport or rotate signing assets only when the evidence shows that an asset is incomplete, duplicated, damaged, or unavailable.
This guide is for independent developers whose Archive succeeds in a graphical macOS session but fails after SSH login. It also targets small teams using scripts, fastlane, or a self-hosted runner for unattended signing. Developers who migrated a build Mac and imported certificates but still cannot use an Apple Distribution or Developer ID identity will find the same diagnostic path useful.
00Start by preserving the failed signing context
codesign errSecInternalComponent is a generic code signing failure, not a diagnosis. The same message can appear when the process cannot use a private key, when a Keychain is locked, or when the identity and provisioning assets do not form a usable chain. Apple’s code signing troubleshooting material treats the execution context as part of the investigation, especially for SSH and continuous integration environments. Review the Apple code signing troubleshooting discussions before assuming that a certificate must be replaced.
Before clearing caches, deleting identities, or revoking anything, record:
- The macOS username that actually runs
codesign,xcodebuild, the script, or the runner. - Whether the command runs from a graphical login, SSH, launch service, scheduler, or CI agent.
- The exact Keychain path used by the build.
- The signing command and its relevant arguments.
- The stage that fails: direct
codesign, Xcode Archive, export, or upload. - The bundle identifier, Team ID, signing identity label, and profile name after sensitive values are masked.
- The complete error context, with passwords, private paths, tokens, and certificate hashes redacted.
Do not treat a successful security find-identity result as proof that signing will work. It only tells the operator that a matching-looking identity is visible in the current search context. The signing process still needs access to the private key and must be able to satisfy the product’s entitlements and profile requirements.
01First comparison: reproduce the same task in two sessions
The fastest useful baseline is not a new certificate. It is a controlled comparison.
Use the same macOS user, the same unsigned test product, the same identity selector, and the same Keychain path. Run the smallest safe signing operation in a graphical Terminal session, then repeat it in a new SSH session. Avoid changing the project between tests. If the graphical command succeeds and SSH fails, the difference is probably session state, Keychain availability, or authorization.
A basic inventory can look like this, with placeholders kept deliberately generic:
whoami
security list-keychains
security default-keychain
security find-identity -v -p codesigning <KEYCHAIN_PATH>
codesign -dvvv <APP_OR_FRAMEWORK_PATH>
The placeholders must be replaced only inside the local environment:
<KEYCHAIN_PATH>: the Keychain searched by the build user.<APP_OR_FRAMEWORK_PATH>: a disposable test product.<IDENTITY_SELECTOR>: a certificate name or a redacted hash used by the project.
If the command fails before it reaches the expected identity, capture that fact. If it identifies the certificate but fails when accessing the private key, capture that instead. Apple’s Keychain documentation explains the Keychain as a protected store, so availability and access control are separate questions from certificate visibility.
| Comparison point | Graphical session succeeds, SSH fails | Both sessions fail |
|---|---|---|
| First suspicion | Locked login Keychain, different search list, or interactive authorization | Incomplete identity, missing private key, trust issue, profile mismatch, or damaged product |
| First action | Compare user, Keychain path, unlock state, and tool authorization | Inspect the certificate-private-key pair and trust chain |
| Certificate rotation | Usually premature | Consider only after evidence confirms an unusable asset |
| Acceptance test | Fresh SSH session and logout state | Direct signing, Archive, export, and upload chain |
This distinction prevents a common waste cycle: revoking a valid Apple Distribution certificate when the real failure is that the SSH process cannot unlock or use the existing private key.
02Second step: verify the complete signing identity
A code signing identity is more than a certificate label. The certificate contains public information. Signing also requires the corresponding private key. Apple’s TN3161 technical note on code signing certificates describes the certificate structure and the relationship between the certificate and its signing capabilities.
Check the identity under the exact build user, not under an administrator account used for maintenance. In Keychain Access, expand the certificate entry and confirm that a private key is associated with it. A certificate displayed without its private key is not a complete identity for signing.
Then check for these conditions:
- The certificate is expired or revoked.
- Several certificates have the same display name but different underlying identities.
- The certificate is in one Keychain while the private key is in another.
- The private key belongs to a different certificate request.
- The build user can list the identity but cannot use the private key.
- A distribution identity is being selected for a development profile, or the reverse.
- The project’s signing settings select a stale identity by name instead of a deliberate, verified selector.
Apple’s certificate type overview is the reference for distinguishing certificate purposes. Do not infer that an Apple Distribution certificate is interchangeable with every development or Developer ID workflow. The identity must match the target platform, distribution action, team, entitlements, and provisioning configuration.
The private key check should be performed in the same environment that signs the product. Importing a .cer file alone does not recreate the private key. A complete export and import process must preserve the certificate-private-key relationship, while the Keychain access policy still needs to be made usable by the build tools.
03Repair only the non-interactive Keychain path
When the graphical test succeeds and SSH fails, repair the Keychain context before touching signing assets.
First identify the Keychain that contains the complete identity. Then make that Keychain available to the build user and unlock it through the team’s approved secret-handling method. A generic diagnostic sequence might resemble:
security list-keychains -d user
security default-keychain -d user
security unlock-keychain -p '<KEYCHAIN_PASSWORD_FROM_SECRET_STORE>' '<KEYCHAIN_PATH>'
security find-identity -v -p codesigning '<KEYCHAIN_PATH>'
The password in this example must not be committed to a repository, printed in CI logs, placed in a shell history file, or embedded in a shared script. <KEYCHAIN_PASSWORD_FROM_SECRET_STORE> is a placeholder for a protected secret injection mechanism. The command must execute as the build user. Running it with sudo can create a misleading result because the root environment may use a different home directory, search list, default Keychain, and access policy.
Next, configure the narrowest practical access for the signing tools required by the build. Depending on the workflow, that may include codesign, xcodebuild, and a controlled build wrapper. Do not disable macOS security mechanisms globally. Do not grant broad permanent access merely because a temporary test succeeds.
Important: A Keychain unlock test is not the same as a production approval. After changing access control, repeat the test from a fresh SSH session and confirm that the exact build process—not only an interactive shell—can use the private key.
If a prompt appears in a graphical session but not in SSH, the prompt is evidence of an authorization difference, not proof that the certificate is bad. The durable fix is to define how the unattended job initializes the Keychain and authorizes the required tools. The workflow should fail clearly when initialization cannot complete, rather than continuing with a different default Keychain.
04Third step: separate identity problems from profile and trust problems
Once the private key is accessible, validate the rest of the signing chain. A direct codesign test can pass while an Xcode Archive still fails because Archive signs nested code, applies entitlements, embeds a provisioning profile, and prepares an exportable product.
Use a disposable test project or a controlled release project. Keep the signing mode explicit during diagnosis. Compare:
- The bundle identifier in the project and the profile.
- The Team ID selected by the build.
- The Apple Distribution identity used for release signing.
- The entitlements requested by the app and allowed by the profile.
- Embedded frameworks, extensions, helper tools, and other nested code.
- The profile’s expiration and registered capabilities.
- The export method selected during distribution.
Apple’s instructions for creating an App Store provisioning profile describe the profile’s role in App Store distribution. The profile management guidance should be used before deleting or recreating a profile, because removal can affect other build jobs that still depend on it.
A trust-chain error deserves a different response from a locked Keychain. If the output indicates that a certificate chain cannot be established, inspect the installed intermediate certificates and the certificate’s validity. If the output says that the identity is invalid, determine whether the private key is missing or whether the selected certificate is not appropriate for the operation. If the profile is invalid or mismatched, repair the profile relationship instead of rotating a working private key.
Apple’s Xcode build settings reference is useful when a project appears to select one identity in the interface but a script overrides it. Record the effective build settings in the failing job. A project-level setting, command-line override, environment variable, or export option can silently select a different identity from the one tested interactively.
05Fourth step: rerun the complete Archive and upload path
A green minimal signing command is only an intermediate checkpoint. The actual release path must be tested under the same SSH or runner context.
Use this sequence:
- [ ] Confirm the job prints the expected build username without exposing secrets.
- [ ] Confirm the intended Keychain path and search list.
- [ ] Confirm the complete certificate-private-key identity is visible to that user.
- [ ] Unlock the intended Keychain through the approved secret mechanism.
- [ ] Run a disposable direct
codesigntest against the expected product. - [ ] Run the real Xcode Archive with the release configuration.
- [ ] Inspect nested code, extensions, entitlements, and the embedded provisioning profile.
- [ ] Export the archive using the intended distribution method.
- [ ] Validate the exported app before upload.
- [ ] Perform the upload only after local signing and export validation succeed.
- [ ] Store sanitized logs showing the failure stage and recovery action.
Do not delete all identities as a first-line cleanup. That can break unrelated products, invalidate local assumptions, and make rollback harder. If an identity must be removed, record its scope, affected bundle identifiers, dependent jobs, and restoration method first. The same rule applies to profile deletion and certificate rotation.
06Complete the unattended signing acceptance window
The environment is not recovered merely because one SSH invocation passes. A remote build Mac should survive the states that occur during normal maintenance and release work.
Repeat the real Archive workflow after:
- The graphical user logs out.
- A new SSH connection starts.
- A previous signing task fails and is retried.
- The host is restarted.
- The build runner reconnects without an existing interactive shell.
- The Keychain initialization step runs again.
The acceptance record should identify the session state, build user, Keychain path, signing result, delivery method, and recovery step. It should not contain private keys, passwords, authentication tokens, or unredacted certificate identifiers.
If signing works only while a person remains logged into the graphical desktop, the environment is not truly unattended. At that point, the team has two choices: continue repairing the current Mac’s user and Keychain lifecycle, or move the build to a persistent remote Mac environment where the required user context, root access, and continuous availability can be managed deliberately. The second option does not remove the need for correct Apple signing assets; it removes one class of last-minute desktop-state failure.
07FAQ
Why does the same command behave differently over SSH?
A graphical login and an SSH session can expose different default Keychains, environment variables, authorization prompts, and user contexts. Run whoami, inspect the Keychain search list, and compare the exact identity output in both sessions. If only SSH fails, treat session and access state as the primary branch of the investigation.
Should an Apple Distribution certificate be regenerated immediately?
No. errSecInternalComponent does not establish that an Apple Distribution certificate is defective. Rebuild the evidence first: certificate validity, matching private key, Keychain access, trust chain, profile, and effective Xcode settings. Rotation is justified only when the existing digital identity cannot be restored or is confirmed to be invalid, duplicated, or incomplete.
What proves that a private key matches the certificate?
The certificate and private key should appear as one associated identity in the Keychain used by the build user. A certificate listed by security find-identity is insufficient on its own. Test private-key use from the real signing process, because a different Keychain or access-control rule can make an apparently complete identity unusable to SSH.
How can a remote Mac sign after logout?
The build must explicitly select and initialize the intended Keychain without relying on a desktop prompt. Its secret must come from protected storage, and only the required tools should receive access to the private key. Validate this after logout, reconnect, retry, and restart. A workflow that needs manual approval during release is not a finished unattended setup.
Why does identity discovery succeed while signing fails?
Identity discovery and private-key authorization are different checks. The visible certificate may lack its private key, belong to another Keychain, or be blocked by access control. The selected profile, entitlements, nested code, or trust chain can also fail later. Compare the complete Archive output with the direct identity inventory before changing assets.
08Choose a stable remote build path after the repair
If the current arrangement requires a developer to keep a graphical session open, depends on an unpredictable authorization dialog, or loses the Keychain context after maintenance, the immediate workaround is not a reliable long-term release process. A local Mac can provide excellent control, but dedicating hardware to a 24-hour signing and Archive workflow adds purchase cost, maintenance responsibility, physical access requirements, and a single-machine recovery burden. A generic cloud runner can reduce hardware ownership, yet it may introduce limited macOS control, session differences, restricted Keychain behavior, or inconsistent persistence.
For teams that need a real Mac only during release preparation, migration testing, or a temporary CI workload, NUKCLOUD remote Mac access offers a way to operate a hosted Mac through remote access while preserving a dedicated build-user workflow. Before choosing it, verify the required macOS version, physical-device needs, persistence expectations, and signing-asset policy. Teams needing a specific regional ordering path can also review the available remote Mac plans.
The sensible next action is to run one complete Archive after logout, SSH reconnection, and restart. If that test passes, the signing environment is supportable. If it fails only because the current Mac cannot preserve the required user and Keychain state, a continuously available remote Mac is often a cleaner operational fit than repeatedly repairing the release machine during an urgent submission.