Help us understand the problem. What is going on with this article?

cap deploy で Permission denied(public key) が出る。

More than 5 years have passed since last update.

RailsでCapistranoを使ってGitHubに置いてあるコードを本番環境にデプロイする運用をしていたところ、突如、publickeyまわりのエラーが出てデプロイできなくなったので、メモっておきます。

発生したエラー(抜粋)

> cap deploy
  * executing "if [ -d /home/user/app/shared/cached-copy ]; then cd /home/user/app/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 2f0ada48590756cfb37c2fcbdab605ed229759d9 && git clean -q -d -x -f; else git clone -q -b master git@github.com:foo/bar.git /home/user/app/shared/cached-copy && cd /home/user/app/shared/cached-copy && git checkout -q -b deploy 2f0ada48590756cfb37c2fcbdab605ed229759d9; fi"
 ** [production_server :: out] Permission denied (publickey).
 ** fatal: The remote end hung up unexpectedly

エラー発生後に試したみたこと

  • GitHub上のプライベートリポジトリへのpushやpull → できる(=公開鍵認証が通る)
  • 本番サーバにもSSHでログイン → できる(=公開鍵認証が通る)

対処法

> ssh-add

以上です。

config/deploy.rbssh_options[:forward_agent] = trueを指定していたにも関わらず、ssh-agentにid_rsaが登録されていませんでした。

ssh-agentについてはssh-agentの基本あたりを見てもらったほうがわかりやすいと思います。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした