I Like
I Like

Reputation: 1847

Rails Capistrano Authentication fail error

I'm following a tutorial to host my Rails 6 application on AWS using Capistrano3, Puma web server and nginx. I am in the final stages, but keep getting an Authentication failed error when I try to deploy my Ruby on Rails application using Capistrano. The command I am using is cap production deploy. I created a ssh key pair, added the public key to my Github repo containing the application code, and added the private key file path to the below snippet in the file: /Users/edward/Project/EdwardBlog/blog/config/deploy/production.rb

set :ssh_options, { 
  forward_agent: true, 
  auth_methods: %w[publickey],
  keys: %w[/Users/edward/.ssh/id_rsa]
}

I can ssh into github like so ssh -T [email protected] and I double checked the key pair matches the public SSH key I added to my github account. I also added the private key to ssh-agent using ssh-add -l

I also tried to deploy the app using my password, but still had no luck when I entered my github account password at the prompt:

set :ssh_options, {
   keys: %w(/Users/edward/.ssh/id_rsa),
   forward_agent: true,
   auth_methods: %w(password)
 }

I don't know why it's not authenticating using the credentials locally. Would appreciate any possible solutions or workarounds.

Here is my message when running the command cap production deploy --trace:

#<Thread:0x00007f9b70963d00@/Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
    12: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
    11: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `run'
    10: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
     9: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capistrano-3.11.2/lib/capistrano/scm/tasks/git.rake:8:in `block (3 levels) in eval_rakefile'
     8: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:80:in `execute'
     7: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
     6: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `tap'
     5: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
     4: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:130:in `execute_command'
     3: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:177:in `with_ssh'
     2: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/connection_pool.rb:63:in `with'
     1: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/connection_pool.rb:63:in `call'
/Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:263:in `start': Authentication failed for user [email protected] (Net::SSH::AuthenticationFailed)
    1: from /Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/edward/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/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)
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: Authentication failed for user [email protected]


Caused by:
Net::SSH::AuthenticationFailed: Authentication failed for user [email protected]

Tasks: TOP => deploy:check => git:check => git:wrapper
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as [email protected]: Authentication failed for user [email protected]


** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:


Please make sure you have the correct access rights

and the repository exists.

  INFO ---------------------------------------------------------------------------

  INFO START 2020-01-01 13:58:01 -0800 cap production deploy

  INFO ---------------------------------------------------------------------------

  INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv

  INFO [ca90e3ef] Running /usr/bin/env mkdir -p /tmp as [email protected]

 DEBUG [ca90e3ef] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )

  INFO ---------------------------------------------------------------------------

  INFO START 2020-01-01 13:58:35 -0800 cap production deploy

  INFO ---------------------------------------------------------------------------

  INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv

  INFO [cd0c878a] Running /usr/bin/env mkdir -p /tmp as [email protected]

 DEBUG [cd0c878a] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )

  INFO ---------------------------------------------------------------------------

  INFO START 2020-01-01 14:28:49 -0800 cap production deploy

  INFO ---------------------------------------------------------------------------

  INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv

  INFO [a745cde8] Running /usr/bin/env mkdir -p /tmp as [email protected]

 DEBUG [a745cde8] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )

Upvotes: 0

Views: 3096

Answers (1)

Chris Heald
Chris Heald

Reputation: 62638

Authentication failed for user [email protected]

This issue is in shelling into your deploy target as ubuntu, it's not in the connection to Github. Make sure that you can shell into that IP with the ubuntu user, and if so, try adding your SSH key to your agent (ssh-add ~/.ssh/id_rsa or whatever) to ensure that Capistrano can establish an SSH connection to your deploy target machine.

Upvotes: 2

Related Questions