![Gerrit 安装在 ssh 验证时失败](https://linux22.com/image/611481/Gerrit%20%E5%AE%89%E8%A3%85%E5%9C%A8%20ssh%20%E9%AA%8C%E8%AF%81%E6%97%B6%E5%A4%B1%E8%B4%A5.png)
我用了官方指南在 Debian 服务器上安装 Gerrit。现在我卡在了应该验证 ssh 连接是否有效的段落:
ssh [email protected] -p 29418 <-- home pc to server
这是我的情况:在我家的电脑上,我有一个用户帐户bastian
,并且我为 ssh 生成了一个密钥对。在服务器上有一个 root 帐户:root
,一个 gerrit 帐户:gerrit2
,还有一个帐户bastian
。使用 OpenID 登录后,我将公钥添加到 gerrit 的 Web 界面中。根据建议,我还将公钥添加到/root/.ssh/authorized_keys
和/home/bastian/.ssh/authorized_keys
(在服务器上)。然后我在服务器上创建了文件,/home/gerrit2/.ssh/config/
内容如下:
IdentityFile ~/.ssh/id_rsa
详细检查 ssh 连接的结果如下:
OpenSSH_6.0p1 Debian-3ubuntu1, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 130.83.160.104 [130.83.160.104] port 29418.
debug1: Connection established.
debug1: identity file /home/bastian/.ssh/id_rsa 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/bastian/.ssh/id_rsa-cert type -1
debug1: identity file /home/bastian/.ssh/id_dsa type -1
debug1: identity file /home/bastian/.ssh/id_dsa-cert type -1
debug1: identity file /home/bastian/.ssh/id_ecdsa type -1
debug1: identity file /home/bastian/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version GerritCodeReview_2.5.4 (SSHD-CORE-0.5.1-R1095809)
debug1: no match: GerritCodeReview_2.5.4 (SSHD-CORE-0.5.1-R1095809)
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0p1 Debian-3ubuntu1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: RSA e9:fc:38:b3:86:f6:72:47:de:79:59:ba:c6:c6:de:7e
debug1: Host '[130.83.160.104]:29418' is known and matches the RSA host key.
debug1: Found key in /home/bastian/.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
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/bastian/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/bastian/.ssh/id_dsa
debug1: Trying private key: /home/bastian/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).
答案1
在您的.ssh/config
文件中,该IdentityFile
行指的是什么?如果它指向 .pub 文件,您将遇到问题。此外,在日志中提示您输入密码的地方,您是否真的可以输入密码?您可能需要使用类似ssh-agent
.
编辑:经过多次检查并阅读日志和程序文档后,我们发现问题在于登录时未输入用户名。初始设置过程,这种情况可能会发生,不幸的是程序没有向用户发出此信号,我建议他向 Gerrit 团队提交错误报告。顺便说一句,他已经在系统上为用户正确创建了所有内容,但 Gerrit 启动了自己的 Open-SSH 实例,用户名包含在 Gerrit DB 中,而不是系统本身中。
答案2
请将你的id_rsa.pub
填入~/.ssh/authorized_keys
(/home/bastian/.ssh/authorized_keys
)。
记得:
- 使
~/.ssh
目录归 bastian 所有,并将其 chmod 设置为 700 - 使
~/.ssh/authorized_keys
文件归 bastian 所有,并将其 chmod 设置为 600
您可以使用以下方法确保以上内容正确:
cat id_rsa.pub > /home/bastian/.ssh/authorized_keys
chown -R bastian /home/bastian/.ssh
chmod -R go-rwx /home/bastian/.ssh
然后使用此命令进行连接:
ssh -i id_rsa bastian@localhost -p 29418
答案3
您应该将 id_rsa 和 id_rsa.pub 移至 .ssh 目录下。这是 ssh 客户端寻找私钥的默认位置。就您而言,我在 /root 目录中看到它,并且需要位于 /root/.ssh/ 中。如果您想更改该默认位置,则需要修改 .ssh/config 文件以对 ssh 客户端设置进行本地更改,或者修改 /etc/ssh/ssh_config。