LoginSignup
64
64

More than 3 years have passed since last update.

Capistranoで自動デプロイした時に出たSSHKit::Runner::ExecuteError解決法

Last updated at Posted at 2019-01-09

Capistranoでデプロイしようとした時にSSH認証エラーが出ました

プログラミングスクールの課題で作成したアプリを修正してEC2へデプロイしようとしたら
以下のエラーが出たため解決法を記しておきます。

terminal
# プロジェクトのローカルディレクトリで自動デプロイを実行
$ bundle exec cap production deploy

(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@ElasticIP: Authentication failed for user ec2-user@ElasticIP


Caused by:
Net::SSH::AuthenticationFailed: Authentication failed for user ec2-user@ElasticIP

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

エラーの原因

再起動するとSSH鍵が消えてしまうみたいなので .sshディレクトリにて以下のコマンドでSSH鍵を登録し直します。

terminal
.ssh $ ssh-add ~/.ssh/hoge.pem
# 以下のように表示されたら
Identity added: /Users/komaki/.ssh/hoge.pem (/Users/komaki/.ssh/hoge.pem)

再度 "bundle exec cap production deploy" を実行

無事にデプロイが成功しました!
Image from Gyazo

再起動した後でも保持させるには...

以下のコマンドを使用すると、キーチェーンストア(鍵の保管庫)に鍵を登録して再起動後も保持してくれます。

terminal
.ssh $ ssh-add -K ~/.ssh/hoge.pem
64
64
3

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
64
64