skip to Main Content

I am trying to deploy my rails 6 app in an AWS EC2 instance with capistrano.

1. I have created a user called ‘deploy’

2. I added my local’s rd_rsa.pub into the server’s ~/.ssh/authorized_keys

3. net-ssh version 6.1.0*

OUTPUT

/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 [email protected] (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 [email protected]: Authentication failed for user [email protected] (SSHKit::Runner::ExecuteError)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: Authentication failed for user [email protected]
/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 [email protected]
/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

deploy/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, '[email protected]: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 }
......

2

Answers


  1. I’m sure, you haven’t configured your local Github agent and key.

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

    Then re-run this below command to make it work.

    ssh-add id_rsa_key_name
    

    If the above solution does not work. Then do this using the .pem extension too.

    ssh-add ~/.ssh/travel_empire.pem
    
    Login or Signup to reply.
  2. issue: Authentication failed for user [email protected] (Net::SSH::AuthenticationFailed) via capistrano but can ssh directly

    debugging:

    1. sudo tail -f /var/log/auth.log on the server
    2. then tried cap production deploy:check on my local

    if show this message error:

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

    solution:

    1. edited then /etc/ssh/sshd_config
    2. find PubkeyAuthentication then uncomment(remove #)
    3. add PubkeyAcceptedKeyTypes=+ssh-rsa
    4. restart sshd sudo systemctl restart sshd
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search