使用 SSH 并指定凭据时,Git 推送因公钥失败

标签 git maven ssh-keys

我这里有一个奇怪的问题。我们的 Maven 发布插件失败,因为它无法将标签推送到 Git。以下失败:

git push ssh://PU0S:xL8q@git-eim.fg.com/u0r0-SS/workspace-proxy.git workspace-proxy-server-1.10.1
[ERROR] Permission denied (publickey).
[ERROR] fatal: Could not read from remote repository.
[ERROR] 
[ERROR] Please make sure you have the correct access rights
[ERROR] and the repository exists.

如果我远程进入机器并尝试使用表单的 URL 进行推送,我会得到同样的错误:

git push ssh://PU0S:xL8q@git-eim.fg.com/u0r0-SS/workspace-proxy.git

如果我只是使用定义的 Remote 推送,它会成功:

git push origin master

以上内容让我确定 .ssh key 在机器上可用。为什么第一个表单会失败?

最佳答案

Any idea why the following command fails git clone ssh://git-eim.fg.com/u0r0-SS/workspace-proxy.git but the following succeeds ssh://git@git-eim.fg.com/u0r0-SS/workspace-proxy.git?
What is special about git@?

git@ 表示将接收推送的用户将是 git。然后,身份验证由用于 ssh 的公钥管理。
这不同于 PU0S:xL8q,它是一个用户名/密码,仅在使用 https url 时才需要。
对于 ssh url,您永远不会“像您一样”(PU0S)推送,而是作为在服务器端管理 git repos 的帐户推送。
这就是为什么,例如,你总是在 git@github.com 推送。

如果 git push origin master 成功,则意味着与名为“origin”的远程关联的 url 格式正确。
通常 ssh://git@git-eim.fg.com/u0r0-SS/workspace-proxy.git

使用 git remote -v 检查,或者 since git 2.7 , 使用 git remote get-url origin

关于使用 SSH 并指定凭据时,Git 推送因公钥失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38134304/

相关文章:

git - 使用交互式 rebase 在分支中间修改提交需要解决冲突

git - 如何解决 git stash 冲突?

java - 如何运行Maven编译的程序?

linux - ssh-keygen 接受标准输入

linux - 为只有 ssh key 的用户创建密码

git - 在服务器上设置 Git/Bitbucket : Permission Issues

git - 分支自动完成不适用于推送的 git 别名

git - TeamCity 代理错误 “failed to perform checkout on agent. exit code: 128”

eclipse - m2eclipse:在构建依赖项时自动安装 Maven

java - 筛选类的 Spring bean ......或者如何在两个 bean 之间进行选择?