运行 Capistrano 上限生产部署时 SSH 身份验证失败
SSH Authentication fails when running Capistrano cap production deploy
这是我第一次尝试使用 Capistrano 部署 Rails 应用程序。我正在按照 https://ogdenstudios.xyz/blog/how-do-i-deploy-a-rails-6-app-to-amazon-ec-2/ 上的教程部署到 AWS EC2 实例。我的应用程序在 Rails 6 和 运行s 上顺利地在本地主机上运行。我按照教程进行操作,但我在最后一步中存货,当我 运行 cap production deploy
出现以下错误时:
00:00 rbenv:validate
rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
00:00 git:wrapper
01 mkdir -p /tmp
#<Thread:0x00007fd74423aa28 /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
12: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
11: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `run'
10: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
9: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/scm/tasks/git.rake:8:in `block (3 levels) in eval_rakefile'
8: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:80:in `execute'
7: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
6: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `tap'
5: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
4: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:130:in `execute_command'
3: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:177:in `with_ssh'
2: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `with'
1: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `call'
/Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh.rb:268:in `start': Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com (Net::SSH::AuthenticationFailed)
1: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com (SSHKit::Runner::ExecuteError)
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
Caused by:
Net::SSH::AuthenticationFailed: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
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 ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
INFO [7f1cf201] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [7f1cf201] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 13:31:07 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [0bfcc93b] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [0bfcc93b] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 13:50:22 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [cb1eb774] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [cb1eb774] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 14:09:05 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [86bd8328] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [86bd8328] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
我正在添加我的 deploy.rb 文件
# config valid for current version and patch releases of Capistrano
lock "~> 3.14.1"
set :application, "lantiamaster"
set :repo_url, "git@github.com:Robs-v82/lantiamaster.git"
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/home/ubuntu/lantiamaster"
set :use_sudo, true
set :branch, 'master'
# Default value for :format is :airbrussh.
# set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
# Default value for :pty is false
set :pty, true
set :ssh_options, {
forward_agent: true,
user: fetch(:user),
# auth_methods: %w[publickey],
keys: %w[~/server-keys/lantiamaster-key-pair.pem]
}
# Default value for :linked_files is []
# append :linked_files, "config/database.yml"
set :linked_files, %w{config/master.key}
# Default value for linked_dirs is []
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }
# Default value for keep_releases is 5
# set :keep_releases, 5
# Uncomment the following to require manually verifying the host key before first deploy.
# set :ssh_options, verify_host_key: :secure
我是部署新手,不知道问题出在哪里。我创建了 SSH 密钥,并将其保存在我的 ubuntu 虚拟机和我的 Github 帐户中。
AWS ec2 实例需要 pem 密钥才能连接到它,所以你必须告诉 capistrano 使用什么密钥,我认为你需要将此配置添加到你的部署文件中:
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: path_to_pem_key }
这是我第一次尝试使用 Capistrano 部署 Rails 应用程序。我正在按照 https://ogdenstudios.xyz/blog/how-do-i-deploy-a-rails-6-app-to-amazon-ec-2/ 上的教程部署到 AWS EC2 实例。我的应用程序在 Rails 6 和 运行s 上顺利地在本地主机上运行。我按照教程进行操作,但我在最后一步中存货,当我 运行 cap production deploy
出现以下错误时:
00:00 rbenv:validate
rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
00:00 git:wrapper
01 mkdir -p /tmp
#<Thread:0x00007fd74423aa28 /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
12: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
11: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `run'
10: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
9: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/scm/tasks/git.rake:8:in `block (3 levels) in eval_rakefile'
8: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:80:in `execute'
7: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
6: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `tap'
5: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
4: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:130:in `execute_command'
3: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:177:in `with_ssh'
2: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `with'
1: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `call'
/Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh.rb:268:in `start': Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com (Net::SSH::AuthenticationFailed)
1: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com (SSHKit::Runner::ExecuteError)
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
Caused by:
Net::SSH::AuthenticationFailed: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
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 ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
INFO [7f1cf201] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [7f1cf201] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 13:31:07 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [0bfcc93b] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [0bfcc93b] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 13:50:22 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [cb1eb774] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [cb1eb774] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 14:09:05 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [86bd8328] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [86bd8328] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
我正在添加我的 deploy.rb 文件
# config valid for current version and patch releases of Capistrano
lock "~> 3.14.1"
set :application, "lantiamaster"
set :repo_url, "git@github.com:Robs-v82/lantiamaster.git"
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/home/ubuntu/lantiamaster"
set :use_sudo, true
set :branch, 'master'
# Default value for :format is :airbrussh.
# set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
# Default value for :pty is false
set :pty, true
set :ssh_options, {
forward_agent: true,
user: fetch(:user),
# auth_methods: %w[publickey],
keys: %w[~/server-keys/lantiamaster-key-pair.pem]
}
# Default value for :linked_files is []
# append :linked_files, "config/database.yml"
set :linked_files, %w{config/master.key}
# Default value for linked_dirs is []
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }
# Default value for keep_releases is 5
# set :keep_releases, 5
# Uncomment the following to require manually verifying the host key before first deploy.
# set :ssh_options, verify_host_key: :secure
我是部署新手,不知道问题出在哪里。我创建了 SSH 密钥,并将其保存在我的 ubuntu 虚拟机和我的 Github 帐户中。
AWS ec2 实例需要 pem 密钥才能连接到它,所以你必须告诉 capistrano 使用什么密钥,我认为你需要将此配置添加到你的部署文件中:
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: path_to_pem_key }