简体   繁体   English

macOS 上的 SourceTree 不断询问 SSH 密钥密码,如果密码存储在钥匙串中,则挂起

[英]SourceTree on macOS keeps asking for SSH key password, or hangs if password is stored in keychain

I've been happily using SourceTree on my Mac for years and rarely had problems.多年来,我一直在我的 Mac 上愉快地使用 SourceTree,并且很少遇到问题。 A couple of weeks ago after updating macOS it suddenly stopped working altogether.几周前更新 macOS 后,它突然完全停止工作。 Whenever I try to clone/fetch/push/pull/whatever to any of my Git repositories, SourceTree either每当我尝试克隆/获取/推送/拉取/任何东西到我的任何Git 存储库时,SourceTree 要么

  1. keeps asking for my SSH key password over and over again immediately after I enter it (if I don't save it in the keychain), or在我输入后立即一遍又一遍地询问我的 SSH 密钥密码(如果我没有将其保存在钥匙串中),或者
  2. just hangs forever in the progress window if the password is stored in the keychain.如果密码存储在钥匙串中,则只会在进度 window 中永远挂起。

It's not an issue with the repositories.这不是存储库的问题。 It's happening for Github too, with the exact same repos and settings that worked before. Github 也发生了这种情况,其存储库和设置与以前完全相同。 The key has chmod 400, same as before, and it's the default key ~/.ssh/id_rsa.密钥有 chmod 400,和以前一样,它是默认密钥 ~/.ssh/id_rsa。 Tried using the embedded Git in SourceTree and System Git, to no avail.尝试在 SourceTree 和系统 Git 中使用嵌入式 Git,但无济于事。 Another app that I switched to in the meantime works normally.我在此期间切换到的另一个应用程序正常工作。

I can't remember exactly which macOS update caused the issues, but I'm now using the latest macOS Catalina 10.15.4 and SourceTree 4.0.1.我不记得究竟是哪个 macOS 更新导致了这些问题,但我现在使用的是最新的 macOS Catalina 10.15.4 和 SourceTree 4.0.1。 I wiped the disk completely clean and re-installed everything from scratch due to another problem, but it still doesn't work.由于另一个问题,我将磁盘完全擦干净并从头开始重新安装所有内容,但它仍然无法正常工作。 I couldn't find anything about new access restrictions that prevent SourceTree from accessing the key itself, or how I could allow access if that's the case.我找不到有关阻止 SourceTree 访问密钥本身的新访问限制的任何信息,或者如果是这种情况,我如何允许访问。 This is driving me nuts, I've switched to another app in the meantime, but I'd really like to continue using SourceTree if it lets me.这让我发疯了,同时我已经切换到另一个应用程序,但如果允许的话,我真的很想继续使用 SourceTree。

EDIT: All my repos are affected by this problem when I'm using SourceTree on macOS.编辑:当我在 macOS 上使用 SourceTree 时,我的所有存储库都受到此问题的影响。 All repos are used by other people as well, it also works for me on my Mac when I use another app.所有 repos 也被其他人使用,当我使用另一个应用程序时,它也适用于我的 Mac。 Even SourceTree for Windows on my other laptop, all of those work with the same key.即使是我另一台笔记本电脑上 Windows 的 SourceTree,所有这些都使用相同的密钥。

Thanks for the helpful reply and comments.感谢您的有用回复和评论。 Turns out SourceTree doesn't add the servers' fingerprints to the ~/.ssh/known_hosts file, and fails silently.结果 SourceTree 没有将服务器的指纹添加到 ~/.ssh/known_hosts 文件中,并且默默地失败。

Easy fix - navigate to your repo folder on the command line and run a simple git command, for example:轻松修复 - 在命令行上导航到您的 repo 文件夹并运行简单的 git 命令,例如:

git fetch origin --dry-run

Nothing will happen since it's a dry run, but the git executable will ask if connecting to the server is ok, and add it to the known_hosts file.因为它是空运行,所以什么都不会发生,但是 git 可执行文件会询问连接到服务器是否正常,并将其添加到 known_hosts 文件。

I faced a similar issue couple of months ago and this is what worked for me.几个月前我遇到了类似的问题,这对我有用。 * Open Keychain Access * Under Login/Passwords section look for SourceTree application password * Select the password, right click and delete the password * 打开钥匙串访问 * 在登录/密码部分下查找 SourceTree 应用程序密码 * Select 密码,右键单击并删除密码

This time when I entered the password for SourceTree, the app accepted the password without any issues and was saved to the keychain.这一次,当我输入 SourceTree 的密码时,应用程序毫无问题地接受了密码并保存到钥匙串中。

There were a couple of things I did that might have contributed to this issue in the first place.首先,我做的一些事情可能导致了这个问题。 I updated my macOS.我更新了我的 macOS。 Around the same time I also enabled two factor authentication in Github.大约在同一时间,我还在 Github 中启用了两因素身份验证。 Maybe a conflict between the saved password in the keychain vs the password I was supplying after the update caused the issue.可能是钥匙串中保存的密码与我在更新后提供的密码之间存在冲突导致了问题。 Hope this helps.希望这可以帮助。

Nothing worked for me until I added this to my .ssh/config :在我将它添加到我的.ssh/config之前,没有什么对我有用:

UseKeychain yes

According to this post, use these commands in your repo folder, works for me well.根据这篇文章,在您的 repo 文件夹中使用这些命令,对我来说效果很好。

git config credential.helper store
git pull

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM