gpt4 book ai didi

jenkins - SSHKit::Runner::ExecuteError:以 root@co 身份执行时出现异常:Jenkins Job 的 shell 脚本中的用户 root@ 身份验证失败

转载 作者:行者123 更新时间:2023-12-03 08:07:04 26 4
gpt4 key购买 nike

我正在尝试从 Jenkins Job 运行 cap 部署命令。它不断抛出以下错误。我也在部署服务器中添加了 ssh key 。我能够从配置 Jenkins 的服务器成功部署。但是当我运行该作业时,会引发身份验证错误。这对我来说真的很重要。有人可以帮忙吗?

Started by user admin
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/TBuildJob
[TBuildJob] $ /bin/bash -l /tmp/jenkins16881638870572548750.sh
Deploying Job has started
Script executed from: /var/lib/jenkins/workspace/TBuildJob
jenkins

jenkins
** Invoke dev1 (first_time)
** Execute dev1
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke rvm:hook (first_time)
** Execute rvm:hook
** Invoke rvm:check (first_time)
** Execute rvm:check
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as root@<server>: Authentication failed for user root@<server>
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
Net::SSH::AuthenticationFailed: Authentication failed for user root@<server>
/usr/local/rvm/gems/ruby-2.3.1/gems/net-ssh-4.2.0/lib/net/ssh.rb:254:in `start'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/backends/connection_pool.rb:59:in `call'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/backends/connection_pool.rb:59:in `with'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/backends/netssh.rb:176:in `with_ssh'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/backends/netssh.rb:129:in `execute_command'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:141:in `tap'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:60:in `capture'
/usr/local/rvm/gems/ruby-2.3.1/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:9:in `block (3 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:29:in `run'
/usr/local/rvm/gems/ruby-2.3.1/gems/sshkit-1.15.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => rvm:check
Build step 'Execute shell' marked build as failure
Finished: FAILURE

最佳答案

在 ubuntu 22.04 服务器上使用 Capistrano 进行部署时,我遇到了类似的问题。登录服务器然后尝试部署。检查日志。

$ journalctl -t sshd -b0

Jun 10 04:30:17 xxxx sshd[664]: Server listening on 0.0.0.0 port 22.
Jun 10 04:30:17 xxxx sshd[664]: Server listening on :: port 22.
Jun 10 04:30:17 xxxx sshd[665]: Accepted publickey for ubuntu from xx.xx.xx.xx port 46072 ssh2: RSA SHA256:XXXX
Jun 10 04:30:17 xxxx sshd[665]: pam_unix(sshd:session): session opened for user xxxx(uid=1000) by (uid=0)
Jun 10 04:30:32 xxxx sshd[944]: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]
Jun 10 04:30:32 xxxx sshd[944]: Connection closed by authenticating user ubuntu xx.xx.xx.xx port 46074 [preauth]

更改您的 sshd_config。

$ sudo nano -l  /etc/ssh/sshd_config

添加行

PubkeyAuthentication yes
PubkeyAcceptedKeyTypes=+ssh-rsa

重新启动 sshd 守护进程

sudo systemctl restart ssh.service

干杯!

这对我有用,但稍后需要更改公钥。

$ ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C "comment"
$ ssh-keygen -t rsa-sha2-256 -b 4096 -f ~/.ssh/id_rsa2_256 -C "comment"
$ ssh-keygen -t rsa-sha2-512 -b 4096 -f ~/.ssh/id_rsa2_512 -C "comment"

精彩讨论https://bbs.archlinux.org/viewtopic.php?id=270005

关于jenkins - SSHKit::Runner::ExecuteError:以 root@<server>co 身份执行时出现异常:Jenkins Job 的 shell 脚本中的用户 root@<server> 身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71952049/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com