Capistrano Rails 6 - Net::SSH Authentication failed for user



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

1。我已经创建了一个名为"deploy"的用户

2。我加上了本地的rd_rsa。将~/.ssh/authorized_keys

3。net-ssh version 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

Capfile

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

部署/production.rb

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

deploy.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 }
......

问题:用户ubuntu@xx.xxx.xxx.xxx (Net::SSH::AuthenticationFailed)通过capistrano认证失败,但可以直接SSH

调试:

  1. sudo tail -f/var/log/auth.log在服务器上
  2. 然后尝试cap生产部署:检查我的本地

如果显示此消息错误:

userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth] appear from auth.log

<解决方案/strong>:

  1. 编辑/etc/ssh/sshd_config
  2. 找到PubkeyAuthentication然后uncomment(remove #)
  3. 添加PubkeyAcceptedKeyTypes = +将
  4. 重启sshdsudo systemctl restart sshd

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

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

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

ssh-add id_rsa_key_name

如果上述解决方法无效。然后也使用.pem扩展名执行此操作。

ssh-add ~/.ssh/travel_empire.pem

最新更新