【问题标题】:Capistrano Rails 6 - Net::SSH Authentication failed for user deploy (SSHKit::Runner::ExecuteError)Capistrano Rails 6 - 用户部署的 Net::SSH 身份验证失败(SSHKit::Runner::ExecuteError)
【发布时间】:2022-11-17 08:33:59
【问题描述】:

我正在尝试使用 capistrano 在 AWS EC2 实例中部署我的 Rails 6 应用程序。

1. 我创建了一个名为“deploy”的用户

2. 我将本地的 rd_rsa.pub 添加到服务器的 ~/.ssh/authorized_keys

3. net-ssh 版本 6.1.0*

输出

/home/vijay/.rvm/gems/ruby-2.7.3/gems/sshkit-1.21.2/lib/sshkit/backends/connection_pool.rb:63:in `call': Passing nil, or [nil] to Net::SSH.start is deprecated for keys: user.....
Mechanism 'publickey','password' was requested, but isn't a known type.  Ignoring it.
E, [2022-04-26T17:02:12.656111 #27306] ERROR -- net.ssh.authentication.session[4e84]: all authorization methods failed (tried 'publickey','password')
#<Thread:0x000055d61c59fec8 /home/vijay/.rvm/gems/ruby-2.7.3/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
    12: from /home/vijay/.rvm/gems/ruby-2.7.3/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'....
.../home/vijay/.rvm/gems/ruby-2.7.3/gems/net-ssh-6.1.0/lib/net/ssh.rb:268:in `start': Authentication failed for user deploy@65.0.135.220 (Net::SSH::AuthenticationFailed)
    1: from /home/vijay/.rvm/gems/ruby-2.7.3/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/home/vijay/.rvm/gems/ruby-2.7.3/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as deploy@65.0.135.220: Authentication failed for user deploy@65.0.135.220 (SSHKit::Runner::ExecuteError)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@65.0.135.220: Authentication failed for user deploy@65.0.135.220
/home/vijay/.rvm/gems/ruby-2.7.3/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/home/vijay/.rvm/gems/ruby-2.7.3/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'

Caused by:
Net::SSH::AuthenticationFailed: Authentication failed for user deploy@65.0.135.220
/home/vijay/.rvm/gems/ruby-2.7.3/gems/net-ssh-6.1.0/lib/net/ssh.rb:268:in `start'
/home/vijay/.rvm/gems/ruby-2.7.3/gems/sshkit-
Tasks: TOP => rvm:hook => passenger:rvm:hook => passenger:test_which_passenger

顶文件

require "capistrano/setup"

# Include default deployment tasks
require "capistrano/deploy"

require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git


require "capistrano/rvm"
require "capistrano/rbenv"
# require "capistrano/chruby"
require "capistrano/bundler"
require "capistrano/rails/assets"
# require "capistrano/rails/migrations"
require "capistrano/passenger"
require "capistrano/puma"
require 'sshkit/sudo'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

require 'capistrano/puma'
install_plugin Capistrano::Puma  # Default puma tasks
install_plugin Capistrano::Puma::Workers  # if you want to control the workers (in cluster mode)
install_plugin Capistrano::Puma::Jungle # if you need the jungle tasks
install_plugin Capistrano::Puma::Monit  # if you need the monit tasks
install_plugin Capistrano::Puma::Nginx

部署/生产.rb

server '65.0.135.220', user: 'deploy', roles: %w{web app db}

部署.rb

lock "~> 3.17.0"

set :application, 'travel_empire'
set :repo_url, 'git@github.com:vijayendran91/travel_empire.git' # Edit this to match your repository
set :branch, :master
set :deploy_to, '/home/deploy/travel_empire'
set :ssh_options, {:verbose => :debug, forward_agent: true, auth_methods: %w['publickey','password'], user: fetch(:user), keys: %w(~/.ssh/travel_empire.pem) }
set :bundle_flags, "--deployment"
# set :ssh_options, { forward_agent: true, user: fetch(:user), keys: path_to_pem_key }
......

【问题讨论】:

    标签: ruby-on-rails nginx amazon-ec2 capistrano3


    【解决方案1】:

    我敢肯定,您还没有配置本地 Github 代理和密钥。

    ssh-add -l
    eval "$(ssh-agent -s)"
    

    然后重新运行以下命令以使其工作。

    ssh-add id_rsa_key_name
    

    如果上述解决方案不起作用。然后也使用 .pem 扩展名执行此操作。

    ssh-add ~/.ssh/travel_empire.pem
    

    【讨论】:

    • 自己做过,忘了提。再次尝试没有运气......
    • 刚刚更新了上面的答案。也做最后一个。 @user2609074
    • 刚试过,兄弟……不走运……如果你想要任何具体信息来帮助我,请告诉我……!!
    • 我遇到了类似的失败。我尝试按照上面的建议进行操作,但它不起作用。我也在尝试直接使用 net-ssh 进行调试,这似乎是这里的罪魁祸首。当我在控制台中运行 Net::SSH.start('xxx.xx.xxx.xxx', 'deploy', { verbose: Logger::DEBUG }) 时,我收到相同的“身份验证失败”消息。 net-ssh 似乎无法使用公钥进行身份验证。但是,当我执行 ssh deploy@xxx.xx.xxx.xxx 时,我可以毫无问题地使用 ssh
    • 嗨@DaniG2k,请参阅我对您的问题的回答
    【解决方案2】:

    问题:用户 ubuntu@xx.xxx.xxx.xxx (Net::SSH::AuthenticationFailed) 通过 capistrano 的身份验证失败但可以直接 ssh

    调试:

    1. sudo tail -f /var/log/auth.log 在服务器上
    2. 然后尝试 cap production deploy:check on my local

      如果显示此消息错误:

      userauth_pubkey:密钥类型 ssh-rsa 不在 PubkeyAcceptedAlgorithms [preauth] 出现在 auth.log 中

      解决方案:

      1. 然后编辑 /etc/ssh/sshd_config
      2. 找到 PubkeyAuthentication 然后取消注释(删除#)
      3. 添加 PubkeyAcceptedKeyTypes=+ssh-rsa
      4. 重启sshd sudo systemctl restart sshd

    【讨论】:

      猜你喜欢
      • 2015-09-15
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多