Why this happens
/usr/bin/codesign failed with exit code 1 is not a diagnosis. It is the shell status codesign returns whenever any part of the signing step fails — a missing identity, a bundle identifier that does not match the profile, an ambiguous certificate, a keychain that is locked, or a certificate without its private key. Xcode prints the wrapper line and buries the actual reason one level deeper.
That is why the same message appears for completely unrelated problems, and why “fixes” found online often do nothing for your project. The first job is always to surface the real error text; the second is to compare what you are asking codesign to use against what the provisioning profile actually allows.
Two causes come up again and again: the Code Signing Identity build setting pointing at a profile or certificate that does not match the app’s bundle identifier, and two copies of the same developer certificate living in different keychains so codesign cannot decide which one to use.
How to fix it
1. Expand the error and read the real message
In Xcode’s Issue Navigator, right-click the codesign failed with exit code 1 line and choose the expand option. The transcript then shows the underlying text, for example a message about an identity not being found or a resource envelope that could not be signed.
For the full picture, open the Report navigator (⌘9), select the failed build, and expand the signing step. If you prefer the terminal, run the build there — xcodebuild prints the complete codesign invocation and its stderr:
xcodebuild -scheme YourApp -configuration Debug \
-destination 'generic/platform=iOS' build
You can also verify an already-built product directly:
codesign -vvv --deep --strict build/Debug-iphoneos/YourApp.app
Whatever that command complains about is the thing to fix. Everything below is a checklist of what it usually complains about.
2. Match Code Signing Identity and bundle identifier to the profile
Select the target, open Build Settings, and check two values:
- Code Signing Identity (
CODE_SIGN_IDENTITY) under Code Signing — it must name a certificate your team actually issued, such asApple Development. - Product Bundle Identifier (
PRODUCT_BUNDLE_IDENTIFIER) under Packaging — it must match the App ID the provisioning profile was generated for. Wildcard profiles only match if the identifier fits the wildcard pattern.
If the profile was created for com.example.myapp and the target builds com.example.myapp.debug, signing fails even though both look correct at a glance. Open the profile and read its entitlements to confirm:
security cms -D -i ~/Library/Developer/Xcode/UserData/Provisioning\ Profiles/<UUID>.mobileprovision
(Older Xcode versions keep the same files under ~/Library/MobileDevice/Provisioning Profiles/.) Look at application-identifier and Entitlements in the output and compare them with your build settings.
The fastest way out of a mismatch is usually to let Xcode manage it: enable Automatically manage signing, pick your team, and let Xcode regenerate the profile for the current bundle identifier. Switch back to manual signing only when you need a specific profile.
3. Remove duplicate certificates with the same name
This is the cause that produces the most confusing version of the error. If two copies of your developer certificate share the same common name but live in different keychains, codesign cannot tell which one to use and exits with status 1.
List the identities codesign can see:
security find-identity -v -p codesigning
If the same name appears twice with different SHA-1 hashes, you have duplicates. Open Keychain Access, select My Certificates in each keychain (login and System, plus any custom keychain you added), sort by name, and delete the stale copy — keep the one that has a private key nested beneath it. Then lock and unlock the keychain once so the change is picked up.
On a build machine, also confirm the keychain is unlocked before the build runs:
security unlock-keychain -p "$KEYCHAIN_PASSWORD" ~/Library/Keychains/login.keychain-db
4. Confirm the certificate has its private key
A certificate without a matching private key cannot sign anything. In Keychain Access, expand the certificate row: if there is no private key underneath, the certificate was imported without its .p12 companion or was copied from another Mac.
Revoke the certificate in the developer portal, create a new one, and download it together with its private key. If you are moving to a new machine, export the identity as a .p12 from the original Mac instead of re-downloading only the certificate.
5. Clean the build and re-sign from scratch
Stale products in DerivedData occasionally keep an old signature. Clean the build folder with ⇧⌘K, delete the project’s DerivedData entry, and build again. If the app was previously signed with a different team, delete the built .app before rebuilding so codesign is not asked to replace an existing signature it does not own.
How to prevent it
- Keep exactly one copy of each developer certificate per machine, and remove expired or revoked ones from every keychain.
- Prefer Automatically manage signing for day-to-day work; manual profiles drift out of sync with bundle identifiers quickly.
- Never hand-edit the bundle identifier in
Info.plist— change it in the target’s build settings so the profile, entitlements and binary stay aligned. - On CI, unlock the keychain explicitly and import a
.p12that includes the private key. - When a signing error appears, expand it before changing anything; guessing at settings usually adds a second problem.
FAQ
What does exit code 1 from codesign actually mean?
It means the signing operation failed, nothing more specific. codesign returns a non-zero status for every failure mode — missing identity, mismatched identifier, ambiguous certificate, locked keychain — so the useful information is always in the message printed alongside it.
Where do I find the full codesign error in Xcode?
Right-click the error in the Issue Navigator and expand it, or open the Report navigator (⌘9) and expand the signing step of the failed build. Running xcodebuild in Terminal gives the same output without any truncation.
Can a duplicate certificate really break signing?
Yes. If two certificates share the same common name in different keychains, codesign has no way to choose between them and fails. security find-identity -v -p codesigning shows the duplicates by hash, and deleting the stale copy resolves it.
Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.