【问题标题】:Git wants a password even though its setup with key authentication即使设置了密钥身份验证,Git 也需要密码
【发布时间】:2016-11-18 18:15:00
【问题描述】:

我在使用 git 时遇到了问题。当我尝试访问存储库时,git 会自动提示输入密码,即使 gitserver 上禁用了通过密码进行身份验证。

我的 ssh 配置如下(主机名/存储库是匿名的):

host gitserver
  user gitolite
  hostname server.example.com
  identityfile ~/.ssh/gitolite

当我尝试克隆 repo 但由于密码请求而失败时:

git clone gitolite@server.example.com:repository
Cloning into 'repository'...
gitolite@server.example.com's password: 

~/.ssh 文件夹及其内容设置为权限 700,如 here 所述(我尝试过的许多事情之一)。

谁有办法解决这个问题?

编辑:

其他克隆尝试以完全相同的方式失败

git clone gitserver:repository
Cloning into 'repository'...
gitolite@server.example.com's password: 

编辑2:

ssh -Tv gitserver

产生以下输出:

debug1: Reading configuration data /home/username/.ssh/config
debug1: /home/username/.ssh/config line 1: Applying options for gitserver
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to server.example.com [1.2.3.4] port 22.
debug1: Connection established.
debug1: identity file /home/username/.ssh/gitolite type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/username/.ssh/gitolite-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-4
debug1: match: OpenSSH_6.0p1 Debian-4 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0p1 Debian-4
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA 00:df:a5:58:af:45:be:eb:62:65:07:5d:85:20:7c:98
debug1: Host 'server.example.com' is known and matches the RSA host key.
debug1: Found key in /home/username/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/username/.ssh/gitolite
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: /home/username/.ssh/gitolite
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
gitolite@server.example.com's password:

【问题讨论】:

  • 我很困惑,因为您在配置文件中有“用户 git”,并且还将不同的用户传递给 git clone (gitolite@)。也许这就是它不使用配置的原因。
  • 您似乎也使用了不同的主机名(命令行中为server.example.com,而配置中为gitserver)。
  • @RemcoGerlich 这是问题中的错字,我更正了那个
  • @robertklep gitserver 只是一个同义词,如果我使用与主机名相同的名称,它不会改变任何东西
  • 密钥被拒绝。您可能没有正确设置身份验证。

标签: git ssh gitolite


【解决方案1】:

如果要使用gitolite使用的私钥,ssh url必须是:

git clone gitserver:repository

这将使用 ~/.ssh/gitolite 私钥,将您标识为 gitolite 服务器上的 git。

【讨论】:

  • 不幸的是,我之前也尝试过,结果完全相同。
  • 然后试试ssh -Tv gitserver:这行得通吗?只要它不起作用,就不可能进行gitolite操作。请注意,使用此特定密钥对于克隆 gitolite-admin 很有用。它不应该用于克隆 Gitolilte 管理的任何 git Repo。
  • gitolite@server.example.com:repositorygitserver:repository 不同:第一个依赖于默认的id_rsa(.pub) ssh 密钥。第二个使用 gitolite 私钥。
  • 正如我在之前的帖子中所说,不幸的是,两次尝试都会导致相同的情况
  • 您发布的 ssh 命令似乎有效,因为我在生成的调试输出中看不到任何错误
【解决方案2】:

找出密码提示的原因。

显然,先前用于增加 git 中支持的文件大小的 gitolite 命令之一无法运行,这导致 gitolite 的后续关键更新卡在队列中。

因此~/.ssh/known_hosts在服务器端从未被gitolite更新,导致key的衰落。

【讨论】:

  • 很好的反馈。 +1。感谢您让我们所有人都知道问题所在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-18
  • 1970-01-01
  • 2021-01-06
  • 1970-01-01
  • 2017-06-21
  • 1970-01-01
相关资源
最近更新 更多