我正在尝试连接到我的 VPS 上托管的 gerrit。我正在使用 Windows 版 Git Bash。我在 GitBash 中使用 ssh-keygen 生成了 SSH 密钥,并在 gerrit 服务器上添加了密钥。 当我运行
ssh -p 29418 <username>@<gerrit-server>
时,我会看到下面的欢迎消息
**** Welcome to Gerrit Code Review ****
Hi Full Name, you have successfully connected over SSH.
Unfortunately, interactive shells are disabled.
To clone a hosted Git repository, use:
git clone ssh://username@<gerrit-server>:29418/REPOSITORY_NAME.git
但是当我通过运行以下命令克隆存储库时
git clone ssh://<username>@<gerrit-server>:29418/project-name.git
我在 Git Bash 终端中看到以下错误
Cloning into 'project-name'...
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我无法理解发生了什么以及如何在我的机器中成功克隆我的项目。有人可以帮我解决这个问题吗?
更新1:
我仍然无法弄清楚问题是什么,但我只想分享一些现在正在发生的奇怪的事情。我创建了另一个 SSH 密钥,这次我为 SSH 密钥添加了密码。我也在 SSH 服务器上添加了该密钥。通常,当密钥附加有密码时,Git Bash 终端应要求输入密码来解锁私钥。
现在发生的情况是,如果我通过运行命令 ssh gerrit 服务器
ssh -p 29418 <username>@<gerrit-server>
它会要求我解锁密码,这意味着它使用正确的 ssh 密钥并显示 Gerrit 欢迎消息 SSH_exchange_identification
错误的原因。在克隆之前我还需要执行其他步骤吗?我是否需要进行任何 Git 设置才能成功克隆 Git 存储库?
配置你的 git 设置 -> config
添加
user.name
和 email
(在您的 gerrit 设置中使用)
我也面临同样的问题,它不适用于最新版本的 Git。
对于 git 版本 - 2.29.3,它对我来说工作得很好。
如果您想确定正在使用哪个 ssh 密钥,请尝试在 .ssh 文件夹中添加一个名为 config 的文件,并包含以下内容。这将帮助您识别正在使用哪个 ssh 密钥 -
# Gerrit
Host gerrit.*.com
host gerrit.*.com
user user_name
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
我也有同样的问题。
当我跑步
ssh -p 29418 <username>@<gerrit-server> gerrit ls-projects
时,
我将看到项目列表,但是当我克隆存储库时,我看到相同的错误。