简体   繁体   English

加载密钥:权限被拒绝詹金斯

[英]load key : permission denied jenkins

I am trying to run a multibranch job in jenkins .我正在尝试在 jenkins 中运行多分支工作。 Codes are placed in git.代码放在 git 中。 While running the job I am getting access rights issue.在运行作业时,我遇到了访问权限问题。 While generating the ssh-keygen in jenkins getting the permission denied error.在 jenkins 中生成ssh-keygen时出现权限被拒绝错误。

Configuring in ubuntu box.在 ubuntu 框中配置。

  1. Tried copying the id_rsa and id_rsa.pub from /root/.ssh but its doesnt copy anything in id_rsa or allow to edit the file manually.尝试从 /root/.ssh 复制 id_rsa 和 id_rsa.pub 但它不会复制 id_rsa 中的任何内容或允许手动编辑文件。
 git ls-remote -h git@github.com:****/*****1.git HEAD
The authenticity of host 'github.com ("IP Address")' can't be established.
RSA key fingerprint is SHA256:********************Y8.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/var/lib/jenkins/.ssh/known_hosts).
Load key "/var/lib/jenkins/.ssh/id_rsa": Permission denied
Permission denied (publickey).
fatal: Could not read from remote repository.

Load key "/var/lib/jenkins/.ssh/id_rsa": Permission denied is about reading the local private ssh key on your local file system, and has nothing to do with the remote server. Load key "/var/lib/jenkins/.ssh/id_rsa": Permission denied是关于读取本地文件系统上的本地私有 ssh 密钥,与远程服务器无关。

Make sure that you have read permission for your ssh key.确保您对 ssh 密钥具有读取权限。 (I experienced this issue when my key was encrypted by my Windows host, but my Docker container couldn't decrypt it.) (当我的密钥被 Windows 主机加密时,我遇到了这个问题,但我的 Docker 容器无法解密它。)

You could also always just generate a new key and try that one.您也可以始终只生成一个新密钥并尝试使用该密钥。

This error is coming because you might have copied the id_rsa file into the location /var/lib/jenkins/.ssh/ .出现此错误是因为您可能已将 id_rsa 文件复制到/var/lib/jenkins/.ssh/位置。 You might have copied the file either from local machine to the remove server or created the keys at root level.您可能已将文件从本地计算机复制到删除服务器或在根级别创建了密钥。 So file "id_rsa" have owner as root and you are trying to access this file from your jenkins.因此,文件“id_rsa”的所有者为 root,您正尝试从 jenkins 访问此文件。 Jenkins should be the owner to read the file. Jenkins 应该是读取文件的所有者。 Below are the steps to check and fix this issue以下是检查和解决此问题的步骤

  1. SSH into jenkins server and first run command sudo su and then go inside /var/lib/jenkins/.ssh/ . SSH 进入 jenkins 服务器并首先运行命令sudo su然后进入/var/lib/jenkins/.ssh/
  2. Run command ls -la运行命令ls -la
  3. you will see owner as root root of id_rsa file like -r--------. 1 root root 18 Sep 1 10:00 id_rsa您将看到所有者为 id_rsa 文件的根根,如-r--------. 1 root root 18 Sep 1 10:00 id_rsa -r--------. 1 root root 18 Sep 1 10:00 id_rsa
  4. Run command chown jenkins:jenkins id_rsa .运行命令chown jenkins:jenkins id_rsa This command will change owner of the file from root to jenkins.此命令会将文件的所有者从 root 更改为 jenkins。 Now the same line looks like -r--------. 1 jenkins jenkins 18 Sep 1 10:01 id_rsa现在同一行看起来像-r--------. 1 jenkins jenkins 18 Sep 1 10:01 id_rsa -r--------. 1 jenkins jenkins 18 Sep 1 10:01 id_rsa
  5. Now trying running the jenkins job again, it will successfully run.现在再次尝试运行 jenkins 作业,它将成功运行。
  6. Make sure your id_rsa file should have right permissions.确保您的 id_rsa 文件应该具有正确的权限。 If not for safer side do chmod 400 id_rsa如果不是为了更安全的一面,请执行chmod 400 id_rsa

I have solved the issue by following above steps.我已经按照上述步骤解决了这个问题。

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

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