Jenkins - SSH 存储库 URL 无法连接

Jenkins - SSH Repository URL unable to connect

我在CentOS上安装了Jenkins,还安装了git插件,以便使用Bitbucket。在源代码管理中添加存储库 URL 时,HTTPS 运行良好,但是当我添加 SSH url 时,弹出以下错误 -

Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h git@bitbucket.org:ash_dy/test_1.git HEAD" returned status code 128:
stdout: 
stderr: Host key verification failed. 
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

我用谷歌搜索了这个,但没有找到我的问题的任何答案,我想使用 ssh 而不是 Https,所以请帮忙。

尝试在您的计算机上以 jenkins 用户身份登录。然后执行:

ssh -T git@bitbucket.org

此命令将验证您与 bitbucket 之间的 ssh 配置。可能你的 ssh key 不对。

我终于找到了解决我的问题的方法,我在这里发布给其他人。

  1. 通过编辑 /etc/passwd/ 并将 /bin/false 更改为 /bin/bash 来为 jenkins 用户配置 shell。

  2. su - jenkins。注意 jenkins 用户的家是 /var/lib/jenkins

  3. ssh-keygen 然后 cat .ssh/id_rsa.pub 并将此密钥复制到您的 bitbucket 帐户

  4. ssh git@bitbucket.org 在 .ssh/known_hosts

  5. 中设置 bitbucket ssh 密钥

现在您应该可以从 Jenkins 访问 bitbucket。

引用link.