Deployment to EC2 fails with Net::SSH::AuthenticationFailed error

Asked 2 years ago, Updated 2 years ago, 136 views

I would like to deploy the application I created in Rails to EC2 in Capistrano 3.4, but after executing the following command, an error occurred and I cannot deploy it.

  • EC2
  • Rails4
  • Unicorn
  • Nginx
  • Capistrano 3
[ec2-user@ip-172-31-30-10ec2_test_app]$pwd
/var/www/ec2_test_app/ec2_test_app

[ec2-user@ip-172-31-30-10ec2_test_app] $bundle exec cap production deploy
 (Backtrace restricted to imported tasks)
CAPABORTED!
Net::SSH::AuthenticationFailed:Authentication failed for user [email protected]
Tasks: TOP=>rbenv:validate
(See full trace by running task with --trace)

http://qiita.com/SanoHiroshi/items/d7942d66678f0d60f0ed

usernginx;
worker_processes auto;
error_log/var/log/nginx/error.log;
pid/var/run/nginx.pid;
events {
    worker_connections2048;
}

US>http{
    root/var/www/ec2_test_app/current;
    upstream unicorn-server {
        server unix: /var/www/ec2_test_app/shared/tmp/sockets/unicorn.sock
        fail_timeout = 0;
     }
   server{
      listen80;
      client_max_body_size4G;
      server_name32.826.472.663;
      keepalive_timeout80;
     access_log/var/log/nginx/access.log;
     error_log/var/log/nginx/error.log;
     root/var/www/ec2_test_app/current;
     location~^/assets/{
        include/etc/nginx/mime.types;
        root/var/www/ec2_test_app/current/public;
     }
     location / {
           proxy_pass http://unicorn-server;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header Host $host;
     }
     error_page500502503504/500.html;
     location=/500.html{
         root/var/www/ec2_test_app/current/public;
     }
  }
} 
 group:production,:staging do
 gem 'unicorn'
end

group —Development do
gem 'capistrano', '~>3.4'
gem 'capistrano-rails', '~>1.1', require: false
gem 'capistrano-bundler', '~>1.1', require: false
gem'capistrano-rbenv', '~> 2.0', require: false
gem'capistrano3-unicorn'
end
require'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require'capistrano/rbenv'
Dir.glob("lib/capistrano/tasks/*.rake").each {|r|importr}
set:application, 'ec2_test_app'
set:repo_url, '[email protected]:hoge-fuga/ec2_test_app.git'
set: branch, 'master'

set:deploy_to, '/var/www/ec2_test_app/ec2_test_app'
set: keep_releases, 5
set:rbenv_type,:user
set:rbenv_ruby, '2.3.0'
set:rbenv_map_bins, %w {rakegem bundle ruby rails}
set:rbenv_roles,:all
set: linked_dirs, %w {bin log tmp/backup tmp/pids tmp/cache tmp/sockets vendor/bundle}
after 'deploy:publishing', 'deploy:restart'
namespace —deploy do
  task —restart do
   invite 'unicorn:restart'
  end
end
application='reserve-hacker'
worker_processes2
app_path="/var/www/ec2_test_app/ec2_test_app"
listen "#{app_path}/shared/tmp/sockets/unicorn.sock"
pid "#{app_path}/current/tmp/unicorn.pid"
timeout 60
preload_app true
stdout_path "#{app_path}/current/log/production.log"
stderr_path "#{app_path}/current/log/production.log"
GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly=true
 set:stage,:production
set: rails_env, 'production'
server '32.826.472.663', user: 'ec2-user',
roles: %w {webappdb}
set: ssh_options, {
 keys: File.expand_path('~/.ssh/id_rsa.pem)')
}

Please advise me why the error occurred and I cannot deploy it.

Also, the screen of Nginx that I had been able to see until now was displayed 404 Not Found even if I hit the URL below, and I suddenly couldn't see it.
http://192.0.2.100 (Number is appropriate)
I would also like you to advise me on the cause.

Thank you for your cooperation.

ruby-on-rails capistrano

2022-09-30 21:17

1 Answers

(From comments)

 set: ssh_options, {
 keys: File.expand_path('~/.ssh/id_rsa.pem)')
}

When I changed the key path description from ssh for github to ssh for ec2 instance, the error was resolved and it now works.


2022-09-30 21:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.