如何从git添加ssh密钥到Jenkins? [英] How to add ssh key from git to Jenkins?

查看:948
本文介绍了如何从git添加ssh密钥到Jenkins?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在本地机器上安装新的jenkins项目,我在 Git Repositories下的源代码管理部分添加了bitbucket repo。 code>



但是我得到一个错误:

 无法连接到存储库:命令git ls-remote -h ssh:// git @< main_link> /< name1> /< name2> .git HEAD返回状态码128:
stdout:
stderr:权限被拒绝(publickey)。
致命:无法从远程存储库读取。

请确保您拥有正确的访问权限
并存在存储库。

我可以从我的控制台运行此命令(也可以执行 git克隆等)



我尝试通过添加凭证 私钥 - 直接输入



据我所知,我的私钥在〜/下。 ssh /

  ls〜/ .ssh / 
cat〜/ .ssh / id_dsa

但是当我从〜/ .ssh / id_dsa输入私人ssh密钥后

更新:
试过这个答案: https://stackoverflow.com/a/15314910/1179925

  sudo -i -u jenkins 
jenkins @ user-VirtualBox:〜$ git clone ssh:// git @< link> /< name1> /< name2> ;. git
克隆到'< name2>'...
权限被拒绝(publickey)。
致命:无法从远程存储库读取。

请确保您拥有正确的访问权限
并存在存储库。


解决方案

解决方案如下:

 #切换到jenkins用户
sudo -i -u jenkins

#获取公共密钥
cat〜 /.ssh/id_rsa.pub

#在github \\\bucket web界面中为jenkins添加公钥。

不知道在哪一步jenkins生成它是关键,但在我的情况下它已经在那里。 p>

I'm trying to setup new jenkins project on local machine, I have added bitbucket repo in Source Code Management section under Git Repositories

But I get an error:

Failed to connect to repository : Command "git ls-remote -h ssh://git@<main_link>/<name1>/<name2>.git HEAD" returned status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Howewer I can run this command from my console (also I can do git clone etc.)

I tried to add ssh key via Add Credentials with option Private Key - Enter directly

As I understand my private key is under ~/.ssh/

ls ~/.ssh/
cat ~/.ssh/id_dsa

but after I have entered private ssh key from ~/.ssh/id_dsa nothing changed, I still get the error.

Update: Tried this answer: https://stackoverflow.com/a/15314910/1179925

sudo -i -u jenkins
jenkins@user-VirtualBox:~$ git clone ssh://git@<link>/<name1>/<name2>.git
Cloning into '<name2>'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

解决方案

Solution is following:

#Switch to jenkins user
sudo -i -u jenkins

#Get public key
cat ~/.ssh/id_rsa.pub

#Add public key for jenkins in github\bitbucket web interface.

not sure on which step jenkins generate it's key, but in my case it was already there.

这篇关于如何从git添加ssh密钥到Jenkins?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆