SourceTree总是权限被拒绝(公钥)

Fra*_*927 3 git macos gitlab atlassian-sourcetree

我将soureTree用于克隆ssh项目。

  1. 我已经创建了SSH密钥
  2. 我已经设置了gitlab ssh密钥设置
  3. 我已经ssh-add“ mysshkey”
  4. 我已经ssh-add -K'mysshkey'

当我打印ssh -T时,我可以在命令行中使其成功。当我git clone时,以ssh方式拉,推...在命令行中仍然有效。

但是在sourcetree中仍然会出现错误:

Permission denied (publickey)
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

jon*_*jon 32

我可以通过将我的 github 密钥添加到 Apple 钥匙串来修复它:

ssh-add --apple-use-keychain ~/.ssh/id_ed25519

  • 伟大的!有效。就我而言,密钥是不同的 - 它是由 Sourcetree 生成的。所以我选择了我的密钥,而不是“id_ed25519”,它起作用了 (2认同)
  • 它对我有用,但每天我都运行这个命令,有什么建议吗? (2认同)

paj*_*nas 6

您收到此消息是因为它无法使用您的 SSH 代理提供给它的任何密钥对您进行身份验证。要验证是否是这种情况,请执行以下操作:

ssh -T 
Run Code Online (Sandbox Code Playgroud)

这将尝试为 Mercurial 创建与它的连接。如果您的密钥已正确加载,您应该会收到类似于以下内容的响应。

如果您没有看到一条消息,这可能是由几个因素引起的,但这些是最常见的:

- 您的公钥未加载

要检查您的公钥是否已加载,请执行以下操作:

  1. 打开浏览器并登录到 origin。

  2. 显示 SSH 密钥页面。它显示任何现有密钥的列表。

  3. 如果您没有列出任何键,请设置一个。

- 您的身份未加载到您的 SSH 代理中

如果您的 SSH 代理不知道提供密钥,则连接将失败。要找出您的 SSH 代理当前提供的密钥并添加它们,请执行以下操作:

$ ssh-add -l
Run Code Online (Sandbox Code Playgroud)

然后,如果您没有看到列出的密钥,请添加它 

ssh-add ~/.ssh/identity
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请查看我们完整的 SSH 问题疑难解答指南。

- 您无权在本地文件系统上创建存储库

如果您收到错误“Permission denied”,也可能是 git 或 mercurial 没有在本地创建项目文件夹的权限。检查您尝试检出项目的目录的权限,并确保您具有写入权限。

1   Right click and "Run as Administrator".
2   Type ssh-keygen
3   Press enter.
4   It will ask you to save the key to the specific directory.
5   Press enter. It will prompt you to type password or enter without password.
6   The public key will be created to the specific directory.
7   Now go to the directory and open .ssh folder.
8   You'll see a file id_rsa.pub. Open it on notepad. Copy all text from it.
9   Go to https://gitlab.com/profile/keys .
10  Paste here in the "key" textfield.
11  Now click on the "Title" below. It will automatically get filled.
12  Then click "Add key".
Run Code Online (Sandbox Code Playgroud)

发现在 /var/log/gitlab/sshd/current 中多次出现一条消息:身份验证被拒绝:文件 /var/opt/gitlab/.ssh/authorized_keys 的所有权或模式错误,之后我更改了该文件的所有权99:users to git:users with: chown git:usersauthorized_keys


小智 5

我下载了SourceTree 2.7.6,并遇到了相同的问题。我认为@ Frankie_0927是正确的,私钥必须命名为id_rsa,并且必须在ssh代理中注册。

对于其他遇到此问题的人:请尝试按照以下链接中的说明生成一对密钥:https : //help.github.com/articles/connecting-to-github-with-ssh/将私钥id_rsa存储在〜/中用户/YOURUSERNAME/.ssh(mac的路径)并在github帐户中发布公钥。然后跑

ssh-add -l
Run Code Online (Sandbox Code Playgroud)

你会看见

The agent has no identities.
Run Code Online (Sandbox Code Playgroud)

所以你跑

ssh-add -K ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)

将密钥添加到ssh代理中。之后,运行

ssh-add -l
Run Code Online (Sandbox Code Playgroud)

再次,您将看到已添加密钥,并且应该解决了问题。