前提・実現したいこと
ここに質問の内容を詳しく書いてください。
Ruby on railsで個人アプリを制作し、
AWS EC2 に手動でデプロイできるようになり、
自動デプロイさせる最後の確認のため、bundle exec cap production deployを行うとエラーが発生しました。
■■な機能を実装中に以下のエラーメッセージが発生しました。
terminal
1uraokayuutarou@uraokayuutarou-no-MacBook nostalgia % raokayuutarou@uraokayuutarou-no-MacBook nostalgia % bundle exec cap production deploy 2#<Thread:0x00007fc402b5a6f8@/Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): 3Traceback (most recent call last): 4 12: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' 5 11: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `run' 6 10: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec' 7 9: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capistrano-rbenv-2.2.0/lib/capistrano/tasks/rbenv.rake:10:in `block (3 levels) in <top (required)>' 8 8: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:61:in `test' 9 7: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute' 10 6: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `tap' 11 5: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute' 12 4: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:130:in `execute_command' 13 3: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:177:in `with_ssh' 14 2: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `with' 15 1: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `call' 16/Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/net-ssh-6.1.0/lib/net/ssh.rb:268:in `start': Authentication failed for user Yutaro.Uraoka@54.248.24.69 (Net::SSH::AuthenticationFailed) 17 1: from /Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' 18/Users/uraokayuutarou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as Yutaro.Uraoka@xx.xxx.xx.xx: Authentication failed for user Yutaro.Uraoka@xx.xxx.xx.xx (SSHKit::Runner::ExecuteError) 19(Backtrace restricted to imported tasks) 20cap aborted! 21SSHKit::Runner::ExecuteError: Exception while executing as Yutaro.Uraoka@xx.xxx.xx.xx: Authentication failed for user Yutaro.Uraoka@xx.xxx.xx.xx 22 23 24Caused by: 25Net::SSH::AuthenticationFailed: Authentication failed for user Yutaro.Uraoka@xx.xxx.xx.xx 26 27Tasks: TOP => rbenv:validate 28(See full trace by running task with --trace) 29uraokayuutarou@uraokayuutarou-no-MacBook nostalgia %
試したこと
まずMysquelに接続できていないかもとエラーログを確認し、
mariadbに接続し直しました。
その後のbundle exec cap production deployを行うと、
sshでエラーが発生しているとterminalをみて考え、
sshを追加しようと、ssh-add ~/.ssh/hoge.pemを実行してみましたが、
うまくいかず質問させていただきました。
ssh-copy-id を使用して登録しようとしても手動で登録しようとしてもうまくいきませんでした。
秘密鍵はキーペアで作成しているものの、公開鍵はどう設定して良いのかわからない状態で終了しています。
terminal
1uraokayuutarou@uraokayuutarou-no-MacBook .ssh % ssh -i xxxxxxxx.pem ec2-user@54.248.24.69 2Last login: Tue Nov 10 06:24:37 2020 from 137.140.5.103.wi-fi.wi2.ne.jp 3 4 __| __|_ ) 5 _| ( / Amazon Linux 2 AMI 6 ___|\___|___| 7 8https://aws.amazon.com/amazon-linux-2/ 9[ec2-user@ip-172-31-45-251 ~]$ sudo systemctl start mariadb 10[ec2-user@ip-172-31-45-251 ~]$ sudo systemctl restart nginx 11Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. 12[ec2-user@ip-172-31-45-251 ~]$ sudo systemctl start nginx 13Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. 14[ec2-user@ip-172-31-45-251 ~]$ ps aux | grep unicorn 15ec2-user 23647 0.0 0.0 119436 968 pts/5 S+ 06:41 0:00 grep --color=auto unicorn 16[ec2-user@ip-172-31-45-251 ~]$ ssh-add ~/.ssh/hoge.pem 17Could not open a connection to your authentication agent. 18[ec2-user@ip-172-31-45-251 ~]$ chmod 600 xxxxxxxxx.pem 19chmod: `nostalgia2020.pem' にアクセスできません: No such file or directory 20[ec2-user@ip-172-31-45-251 ~]$ cd ~ 21[ec2-user@ip-172-31-45-251 ~]$ cd .ssh/ 22[ec2-user@ip-172-31-45-251 .ssh]$ ls 23authorized_keys id_rsa id_rsa.pub known_hosts 24[ec2-user@ip-172-31-45-251 .ssh]$ chmod 600 xxxxxxxxxx.pem 25chmod: `nostalgia2020.pem' にアクセスできません: No such file or directory 26[ec2-user@ip-172-31-45-251 .ssh]$ exit 27ログアウト 28Connection to 54.248.24.69 closed. 29uraokayuutarou@uraokayuutarou-no-MacBook .ssh % ssh -i xxxxxxxxxx0.pem ec2-user@54.248.24.69 30Last login: Tue Nov 10 06:39:30 2020 from 137.140.5.103.wi-fi.wi2.ne.jp 31 32 __| __|_ ) 33 _| ( / Amazon Linux 2 AMI 34 ___|\___|___| 35 36https://aws.amazon.com/amazon-linux-2/ 37[ec2-user@ip-172-31-45-251 ~]$ cd /var/www/nostalgia 38[ec2-user@ip-172-31-45-251 nostalgia]$ ssh-add ~/.ssh/hoge.pem 39Could not open a connection to your authentication agent. 40[ec2-user@ip-172-31-45-251 nostalgia]$ 41 42
登録されているsshの鍵を確認しようとしましたが、
接続を開くことができませんでした。
個人開発のディレクトリに入って実行もしてみましたが、
同じエラー(Could not open a connection to your authentication agent.)が出てきました。
termnal
1https://aws.amazon.com/amazon-linux-2/ 2[ec2-user@ip-172-31-45-251 ~]$ ssh-add -l 3Could not open a connection to your authentication agent. 4[ec2-user@ip-172-31-45-251 ~]$ cd /var/www/nostalgia 5[ec2-user@ip-172-31-45-251 nostalgia]$ ssh-add -l 6Could not open a connection to your authentication agent. 7[ec2-user@ip-172-31-45-251 nostalgia]$
terminal
1https://aws.amazon.com/amazon-linux-2/ 2[ec2-user@ip-172-31-45-251 ~]$ mkdir .ssh 3mkdir: ディレクトリ `.ssh' を作成できません: File exists 4[ec2-user@ip-172-31-45-251 ~]$ touch .ssh/authorized_keys 5[ec2-user@ip-172-31-45-251 ~]$ chmod 700 .ssh 6[ec2-user@ip-172-31-45-251 ~]$ chmod 600 .ssh/authorized_keys 7[ec2-user@ip-172-31-45-251 ~]$ cat ~/.ssh/id_rsa.pub | ssh -i xxxxxxxxx.pem ec2-user@xx.xxx.xx.xx 'cat >> .ssh/authorized_keys' 8Warning: Identity file xxxxxxx.pem not accessible: No such file or directory. 9The authenticity of host '54.248.24.69 (54.248.24.69)' can't be established. 10ECDSA key fingerprint is SHA256:lLzqkqg3f5NLltGU++DHfcxavWesbyq92o4DDfV3Iw8. 11ECDSA key fingerprint is MD5:e0:7f:2f:a5:50:eb:3f:45:bc:b7:bf:31:8d:47:50:34. 12Are you sure you want to continue connecting (yes/no)? y 13Please type 'yes' or 'no': y 14Please type 'yes' or 'no': y 15Please type 'yes' or 'no':
補足情報(FW/ツールのバージョンなど)
設定ファイル
Capfile
# Load DSL and set up stages require "capistrano/setup" # Include default deployment tasks require "capistrano/deploy" # Load the SCM plugin appropriate to your project: # # require "capistrano/scm/hg" # install_plugin Capistrano::SCM::Hg # or # require "capistrano/scm/svn" # install_plugin Capistrano::SCM::Svn # or require "capistrano/scm/git" install_plugin Capistrano::SCM::Git # Include tasks from other gems included in your Gemfile # # For documentation on these, see for example: # # https://github.com/capistrano/rvm # https://github.com/capistrano/rbenv # https://github.com/capistrano/chruby # https://github.com/capistrano/bundler # https://github.com/capistrano/rails # https://github.com/capistrano/passenger # # 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/setup" require "capistrano/deploy" require 'capistrano/rbenv' require 'capistrano/bundler' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' require 'capistrano3/unicorn' # Load custom tasks from `lib/capistrano/tasks` if you have any defined Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
config/deploy.rb
# capistranoのバージョンを記載。固定のバージョンを利用し続け、バージョン変更によるトラブルを防止する lock '3.14.1' set :application, 'nostalgia' set :repo_url, 'git@github.com:uraokayutaro1990/nostalgia.git' set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads') set :rbenv_type, :user set :rbenv_ruby, '2.6.5p114' # どの公開鍵を利用してデプロイするか set :ssh_options, auth_methods: ['publickey'], keys: ['~/.ssh/xxxxxxxxxx.pem'] set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" } set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" } set :keep_releases, 5 after 'deploy:publishing', 'deploy:restart' namespace :deploy do task :restart do invoke 'unicorn:restart' end end
config/deploy/production.rb
server 'xx.xxx.xx.xx', user: 'Yutaro.Uraoka', roles: %w{app db web}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/11/10 10:43
2020/11/10 11:30
2020/11/10 12:02
2020/11/11 00:39
2020/11/11 03:43
2020/11/11 04:21
2020/11/11 04:27
2020/11/11 06:05
2020/11/11 06:10
2020/11/11 06:18
2020/11/11 06:21
2020/11/11 06:36
2020/11/11 06:41
2020/11/11 06:58
2020/11/11 07:29
2020/11/11 07:37
2020/11/11 08:03