LoginSignup
5
3

More than 3 years have passed since last update.

SSHKit::Runner::ExecuteErrorが出たときの話【AWS,Capistrano】

Posted at

はじめに

Capistranoを使用して、AWSに自動デプロイを行なった際に下記のエラーが出たので、備忘録として投稿します。

エラー内容

ターミナル
$  bundle exec cap production deploy

にて、デプロイを試みると、

ターミナル
(中略)
/home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@xx.xxx.xxx.xxx: Authentication failed for user ec2-user@xx.xxx.xxx.xxx (SSHKit::Runner::ExecuteError)
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@xx.xxx.xxx.xxx: Authentication failed for user ec2-user@xx.xxx.xxx.xxx


Caused by:
Net::SSH::AuthenticationFailed: Authentication failed for user ec2-user@xx.xxx.xxx.xxx

Tasks: TOP => rbenv:validate
(See full trace by running task with --trace)

とこのようなエラーが表示されました。SSHの接続の部分で不具合が起こっているのかな?との簡単な予想を立てて、検索をしてみました。

こちらの記事を参考にさせていただき、SSHキーが消えてしまっていると考え、.sshにて下記のコマンドを実行すると解決しました。

ターミナル
$ cd ~/.ssh
.ssh $ ssh-add ~/.ssh/hoge.pem

なぜ、急にキーが消えてしまったのかは不明です。。。。

AWSのデプロイ時のエラーについて

AWSのエラーが起きた際には、下記の確認をまずは行なっていきたいと思います。

・ローカル→GitHubへのpushのし忘れがないか
・GitHubからEC2への反映(git pull origin master)のし忘れはないか
・EC2サーバー側でエラーログの内容確認をする
・データベースが正しく起動しているか
・EC2サーバー側の環境変数は正しく設定できているか
・EC2インスタンスの再起動を行なってみる

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3