Custom SSH Agent doesn't work with Xcode

Short description:


I cannot use my SSH key stored in my password manager Bitwarden to sign my Git commits via Xcode.



Background:


I am using Bitwarden to manage my SSH keys. Basically I have this line in my ~/.zshrc file:


export SSH_AUTH_SOCK=/Users/username/Library/Containers/com.bitwarden.desktop/Data/.bitwarden-ssh-agent.sock


And this is a part of my Git config:

user.signingkey=ssh-ed25519 mykey myemail@xxx.com
gpg.format=ssh
commit.gpgsign=true


This makes sure Git will use sign my commits with the key that I specified. However, the key doesn't really live in my ~/.ssh folder. It lives in my Bitwarden vault. That's why I need to set up that custom SSH Agent to make sure git will be able to sign my commits.


When I run git commit in terminal, my Bitwarden will ask me to approve the usage of my key like this:



If I authorise, my commits will be successfully signed.


Issue:


When I try to commit in Xcode. Xcode isn't really using my custom SSH agent defined in my .zshrc file, as a result, Xcode cannot find my specified SSH key in my Git config, and there will be an error like this:



Workaround:


I have noticed that if I launch Xcode from my terminal like this:


open -a Xcode


There won't be any issue. Bitwarden will ask approval from me, and I can authorise it. Everything works just fine. I suppose this is because launching Xcode from the terminal will inherit environment variables from my .zshrc, whereas launching Xcode directly will not.


Something that I have already tried:


I have tried to set up my SSH_AUTH_SOCK again in launchd agent again like this:


<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>environment.ssh</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>setenv</string>
<string>SSH_AUTH_SOCK</string>
<string>/Users/username/Library/Containers/com.bitwarden.desktop/Data/.bitwarden-ssh-agent.sock</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>


After this I have rebooted my mac. Unfortunately, this doesn't really work either.


How can I get this to work normally? I don't want to launch Xcode from terminal all the time, but I do want it to work with my password manager.



[Edited by Moderator]

MacBook Air

Posted on Jul 13, 2025 01:31 AM

Reply
1 reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Custom SSH Agent doesn't work with Xcode

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.