windows - 推送到现有项目时出现 SSH 错误权限被拒绝(公钥)

标签 windows git ssh gitlab

完成使用 GitLab 的所有必要步骤,这些设置是:

  1. 按照 this link 中的描述创建了一个 rsa
  2. 复制在{my key}.pub 中生成的代码并在GitLab 中添加此代码
  3. 在我现有的存储库中,使用命令 git remote add gitlab git@gitlab.com:ridermansb/breezenhibernateproblem.git 添加到 url
  4. 我尝试进行推送 git push -u gitlab master

我的 .ssh/config

Host gitlab.com
  HostName gitlab.com
  IdentityFile C:\Users\Riderman\.ssh\gitlab_rsa
  IdentitiesOnly yes

错误如下:

警告:将“gitlab.com,54.243.197.170”(RSA) 永久添加到已知主机列表中。 权限被拒绝(公钥)。 致命:无法从远程存储库读取。

请确保您拥有正确的访问权限 并且存储库存在。

我制作了一个展示所有步骤的视频:http://www.screenr.com/euVH

我做错了什么?

最佳答案

看到your screencast之后,我看到您没有 %HOME%\.ssh\config 文件。

这很重要,因为:

  • 默认情况下,ssh 将在 %HOME%\.ssh\id_rsa(.pub)
  • 中查找公钥/私钥
  • 使用类似 scp 的语法(git@gitlab.com:yourRepo,以 ':' 作为分隔符),ssh 可以查找 。 ssh/config 文件用于实际公钥/私钥的位置,使用 gitlab.com 作为所述 config 文件中的条目。

添加 %HOME%\.ssh\config :

Host gitlab.com
  HostName gitlab.com
  IdentityFile C:\path\to\.ssh\gitlab_rsa
  IdentitiesOnly yes

你的 git push -u gitlab master 会工作。

It turned out它还与正确设置 HOME 有关:

%HOME% was not correct.
I configured the variable %HOME% to point to %USERPROFILE% locally and it worked

Mysygit does set HOME , 但如果你在 git-cmd session 之外使用 git,那么你有责任正确设置 HOME

关于windows - 推送到现有项目时出现 SSH 错误权限被拒绝(公钥),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20595713/

相关文章:

java - 布鲁克林起始蓝图 : VMs created but Brooklyn can't SSH in

c - Windows编写的CentOS上运行C程序

c - Windows 上的 GNU Make 模式规则

java - 脚本文件无法创建Java Jar文件

单一开发人员的 Github 工作流程

git - ld : library not found for -lintl on mac os x lion

windows - 无法创建 '/git/index.lock' : File exists - but it doesn't

java - 如何使用批处理命令读取日志文件末尾?

javascript - 通过 Web 浏览器的 SSH 隧道

git突然开始每次都要求SSH key 密码