SourceTree始终拒绝权限(公钥)



我使用soureTree来克隆ssh项目。

  1. 我已经创建了ssh密钥
  2. 我已经设置了gitlab ssh密钥设置
  3. 我用ssh添加了"myshkey">
  4. 我用ssh添加-K"myshkey">

当我打印ssh-T时,我可以在命令行中使它成功。当我以ssh方式gitclone、pull、push时。。。它仍然可以在命令行中工作。(终端(

但在源树中现在仍然得到错误:

Permission denied (publickey)

我该怎么解决?

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

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

ssh-add -l

你会看到

The agent has no identities.

所以你运行

ssh-add -K ~/.ssh/id_rsa

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

ssh-add -l

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

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

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

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

ssh -T 

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

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

-您的公钥未加载

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

  1. 打开浏览器并登录原点。

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

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

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

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

$ ssh-add -l

然后,如果你没有看到你的钥匙被列出,请通过添加它

ssh-add ~/.ssh/identity

有关更多信息,请查看我们的完整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".

发现在/var/log/gitlab/shd/current中多次出现一条消息:身份验证被拒绝:文件/var/opt/gitlab/.ssh/authorized_keys的所有权或模式不正确之后,我将该文件的所有权从99:users更改为git:users,其中:chown git:users authorized_keys

Sourcetree使用文件夹/User/YOURNAME/.ssh/id_rsa下的SSH密钥与Git远程服务器协同工作。

如果您在另一个文件夹中生成密钥,则该密钥在您执行eval "$(ssh-agent -s)"&ssh-add。此外,一旦终端关闭,它就会失效。

ssh密钥必须尚未登录,对于mac try SourceTree->设置->帐户->编辑,现在为ssh连接生成一个密钥对。

现在再试一次。

最新更新