简体   繁体   English

在jenkins gerrit触发器中添加ssh密钥文件:“ /…/ .ssh / id_rsa”不存在

[英]Adding ssh keyfile in jenkins gerrit trigger: “/…/.ssh/id_rsa” does not exist

I installed git, gerrit and jenkins on linux, and I installed gerrit trgger plugin on jenkins. 我在linux上安装了git,gerrit和jenkins,并在jenkins上安装了gerrit trgger插件。 Now I am setting the geerrit server, and trying to add the ssh key file, but it is giving me error "/home/heidi/.ssh/id_rsa" does not exist, and Bad SSH keyfile or password. 现在,我正在设置geerrit服务器,并尝试添加ssh密钥文件,但是它给我错误“ /home/heidi/.ssh/id_rsa”不存在,并且SSH密钥文件或密码错误。

just like the image on its offical website: https://wiki.jenkins-ci.org/display/JENKINS/Gerrit+Trigger (the one in "Administrative Settings") 就像其官方网站上的图片一样: https : //wiki.jenkins-ci.org/display/JENKINS/Gerrit+Trigger (“管理设置”中的那个)

BUT, this location and file both are existing! Why can't these keys be found? 但是,此位置和文件都存在!为什么找不到这些密钥? I had trid the chmod command on .shh file and on those two keys. 我试过在.shh文件和这两个键上使用chmod命令。 but it doesn't works. 但它不起作用。

This is usually a symptom of either 这通常是以下任何一种症状

  1. The key actually not existing (to which the answer from @nafas applies) or 密钥实际上不存在(@nafas的答案适用于此密钥)或
  2. The key is not readable by the jenkins user (which your self-answer alludes to) jenkins用户无法读取该密钥(您的自言自明)

If you are logged into your jenkins server, and you navigate to /var/lib/jenkins/.ssh and do an ls -lA what you would likely see is that "root" or some other user owns the id_rsa private key you are attempting to use. 如果您登录到jenkins服务器,并且导航至/var/lib/jenkins/.ssh并执行ls -lA ,则可能会看到“ root”或其他用户拥有您尝试的id_rsa私钥使用。

[RHEL7.2 /var/lib/jenkins/.ssh]# ls -lA
-rw------- 1 root    root    1675 Jul 11 07:45 id_rsa
-rw-r--r-- 1 root    root     398 Jul 11 07:45 id_rsa.pub
-rw-r--r-- 1 jenkins jenkins  855 Jun 26 19:57 known_hosts

Logged in as root, or using sudo, you will want to change ownership of the user and group to reflect the jenkins user and group like so: chown <user>:<group> file(s) 以root身份登录,或使用sudo登录,您将需要更改用户和组的所有权,以反映jenkins用户和组,如下所示: chown <user>:<group> file(s)

[RHEL7.2 /var/lib/jenkins/.ssh]# chown jenkins:jenkins id_rsa*
[RHEL7.2 /var/lib/jenkins/.ssh]# ls -lA
-rw------- 1 jenkins jenkins 1675 Jul 11 07:45 id_rsa
-rw-r--r-- 1 jenkins jenkins  398 Jul 11 07:45 id_rsa.pub
-rw-r--r-- 1 jenkins jenkins  855 Jun 26 19:57 known_hosts

you can just create a key. 您可以只创建一个密钥。

Log in to your local computer as the user running servers. 以运行服务器的用户身份登录到本地计算机。 In a command prompt, run: 在命令提示符下,运行:

ssh-keygen -t rsa -C "your_email@example.com"

Just press to accept the default location and file name. 只需按接受默认位置和文件名。 If the .ssh directory doesn't exist, the system creates one for you. 如果.ssh目录不存在,系统将为您创建一个。 Enter, and re-enter, a passphrase when prompted. 在提示时输入并重新输入密码。 The whole interaction will look similar to this: 整个交互看起来类似于:

SOURCE: 资源:

https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html

I finally fixed it... 我终于修好了...
post my solution here for someone who might encounter this problem int the future. 将我的解决方案发布给将来可能会遇到此问题的人。
Note that the user of file jenkins which you installed.(in my case, /var/lib/jenkins and the user is "jenkins") 请注意,您安装的文件jenkins的用户。(在我的情况下,为/ var / lib / jenkins,该用户为“ jenkins”)
use "sudo su" then "su jenkins" 使用“ sudo su”,然后使用“ su jenkins”
then generate a pair of ssh key in /var/lib/jenkins 然后在/ var / lib / jenkins中生成一对ssh密钥
it will no longer appear ".....dose not exist" 它不会再出现“ .....剂量不存在”
:) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM