How do I convince SourceTree to store my password in my keychain?
Asked by mark fleming:

Using ST v2.5.1 on Mac OS 10.12.5 connecting to a private git server through ssh. Every operation to/from the server requires I enter my password in the pop-up dialog, twice. I have read through all the support articles I can find and none of the solutions/work-rounds work for me.

The remote URL is of the form myuser@myserver.tld:path/to/origin

I have tried embedded Git and switched ST to use System Git (2.13).Same behaviour using both.

I have carried out push/pull operations in Terminal

I have run ssh-keygen to create new keys

I have created an 'account' for the private URL and enterd my ssh credentials

I have set git config --global credential.helper osxkeychain in terminal

I have checked my keychain and there is no record for ST at the URL of the server. As there is no record I cannot set its permissions (one of the other things I have seen that worked for other people)

Does anyone have any other ideas? Atlassian even suggested that v2.5.x would fix this problem, but not it seems, for me.


Answers:
author: jyo
body: Hi Mark,

With 10.12, I believe there is something you can update a setting to include the Keychain: <https://developer.apple.com/library/content/technotes/tn2449/_index.html>

Also, can you check you SSH config to see if it is pointing to the correct keyfile? (see: <https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-linux-271943168.html>)

I should also note that if you're not using Bitbucket Server, you shouldn't add the account under "Preferences \> Accounts"

Cheers,

Jesse


author: adamrackishotmail
body: This is a brutal thread - after much testing, it seems this is the only real solution, which works great for me

<https://stackoverflow.com/a/35942890/352552>

    git config credential.helper store

then

    git pull

provide user-name and password and those details will be remembered later.

comments: author: Anand Kumar
body: This worked.


author: Riccardo Cohen
body: What I've done with success :

open in hom dir \~/.gitconfig , and add :

\[credential "<https://domaint.private.server>"\]  
username = myusername@me.com  
helper = store

one for each server !

comments: author: mark fleming
body: I have tried all the techniques all the helpful people here have suggested and it still does not put anything into the keychain. I uninstalled the app, switched to the admin user, downloaded another copy, installled that and it DOES put an entry in the keychain and only asks for the password once. So I switched back to my user account, installed a fresh copy of ST and was ever hopeful it would work. It did not.

So my conclusion is this is a permissions issue rather than any kind of unique git setup. Why does ST when running in my user account not store details in my keychain but an admin user does?


author: mark fleming
body: I also tried a different approach, but it only highlights what I believe is the root cause: I tried to clone a new repo. When entering the url I deliberately left off the username part of the url. ST correctly asks me for the authentication details. I entered the username and password. Store Password in Keychain was ticked. After entering the details, it came back to ask me for it all again. This repeated many times until I got bored and clicked cancel instead.

This confirms to me it is a permissions issue with ST negotiating with the keychain incorrectly. Is this fixable?


author: Joseph Hui
body: Hi Mark,

I encountered almost the same problem as you. The symptoms appeared when I used a Windows version SourceTree to update the repository and I thought I'd screwed up the repository because of the CRLF issue. However, I had another Mac that works very well with the repository. On the Mac that has the problem, I notice that the password with key name "\<git server IP\> Access Key for \<user ID\>" was missing. So, I tried to manually create that key but seems I cannot update the "Where" field to "SourceTree". Then, I deleted all password keys for that GIT server in the Keychain, uninstall and SourceTree again, the problem then solved. Now the password key "\<git server IP\> Access Key for \<user ID\>" appear again. Hope this help.


author: mark fleming
body: Thanks. It is now fixed. The important thing that finally solved this was the fact that the keychain had an entry I had not expected. There was an entry for the numerical IP eg 99.100.101.102 as well as its domain name eg mygit.server.com. Once I had cleared the numerical address, SourceTree would create one for the domain address. There's two months of my life I won't get back. But thanks to Joseph, I have now at least got over the password not saving problem.


author: Manju
body: Can you please check your ssh config file once and see if that's fine. And for your kind info, there are new keys on macOS 10.12 to remember password and get the ssh agent use the key - <https://developer.apple.com/library/content/technotes/tn2449/_index.html>

Thanks!

comments: author: mark fleming
body: Thanks for the quick responses guys. I followed technote 2449, added UseKeychain yes and AddKeysToAgent yes. Made no difference.

I verified the agent is running.

I tried the steps to create an identity in \~/.ssh/config for the url I am trying to login to. Again saving the UseKeychain etc but ST still refuses (or is being refused) to place an item in the keychain.

And yes I quit ST and started again after each step of changes to ensure that it was using the latest ssh config

Anything else to try?


author: jyo
body: Can you try restarting the SSH service?

```
sudo launchctl stop com.openssh.sshd
```

(it should automatically restart)