質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

0回答

576閲覧

rails Capistranoでのデプロイでパーミッションエラーとなってしまう

ruby_0ct

総合スコア57

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

1クリップ

投稿2018/05/01 16:16

以下のQiitaを参考にしながら、capistranoでデプロイを行おうとしているのですが、サーバからGithubへの接続でパーミッションエラーとなってしまいます。
Qiita - Conoha vpsサーバーにCentOS6.9 + Rails5系 + MySQL + nginx + unicorn + capistranoでデプロイまで

Qiitaにある項目の7番「capistranoからデプロイ!」でデプロイ可能かチェックするコマンド
bundle exec cap production deploy:check # deploy可能かのチェック
を実行すると、

00:00 git:check 01 git ls-remote git@github.com:〇〇/〇〇.git HEAD 01 Permission denied (publickey). 01 fatal: Could not read from remote repository. 01 01 Please make sure you have the correct access rights 01 and the repository exists. #<Thread:0x00007fb5c8945f90@/Users/macbookpro/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.16.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): Traceback (most recent call last): 1: from /Users/macbookpro/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.16.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/macbookpro/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.16.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as root@サーバのIPアドレス: git exit status: 128 (SSHKit::Runner::ExecuteError) git stdout: Nothing written git stderr: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 01 Permission denied (publickey). 01 fatal: Could not read from remote repository. 01 01 Please make sure you have the correct access rights 01 and the repository exists. #<Thread:0x00007fb5c8946148@/Users/macbookpro/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.16.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): Traceback (most recent call last): 1: from /Users/macbookpro/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.16.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/macbookpro/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.16.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as root@サーバのドメイン名: git exit status: 128 (SSHKit::Runner::ExecuteError) git stdout: Nothing written git stderr: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as root@サーバのドメイン名: git exit status: 128 git stdout: Nothing written git stderr: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Caused by: SSHKit::Command::Failed: git exit status: 128 git stdout: Nothing written git stderr: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Tasks: TOP => deploy:check => git:check (See full trace by running task with --trace)

パーミッションエラーが出てしまいます。
サーバ側・クライアント側共にssh-agentに秘密鍵は追加済みでも、エラーが出る原因がわかりません。
解決策を教えて頂けると助かります。

ちなみにssh -T git@github.comコマンドでは接続を確認しています。

そのほかに行ったこと

ssh-agentのエージェント転送機能を利用する。
Capistranoによるデプロイで発生したgithub接続エラーを解決する

サーバ側の.ssg/configファイルの内容を変更。
Qiita - いきなりcapistranoでdeployができなくなった時の対処法

環境

CentOS7
Nginx 1.12.2
unicorn
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Rails 5.2.0

ファイル

Gemfile

ruby

1gem 'unicorn' 2gem 'capistrano' 3gem 'capistrano3-unicorn' 4gem 'capistrano-rails' 5gem 'capistrano-bundler' 6gem 'capistrano-rbenv'

Capfile

ruby

1require "capistrano/setup" 2require "capistrano/deploy" 3require "capistrano/scm/git" 4install_plugin Capistrano::SCM::Git 5 6require "capistrano/rbenv" 7require "capistrano/bundler" 8require "capistrano/rails/assets" 9require "capistrano/rails/migrations" 10require "capistrano/setup" 11require "capistrano/scm/git" 12require 'capistrano3/unicorn' 13 14set :ssh_options, { 15 keys: %w(/Users/macbookpro/.ssh/github/id_rsa), 16 forward_agent: true, 17} 18 19Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

config/deploy.rb

ruby

1lock "~> 3.10.2" 2 3set :application, "アプリケーション名" 4set :repo_url, "git@github.com:〇〇/〇〇.git" 5 6set :deploy_to, '/var/www/test' 7 8append :linked_files, "config/database.yml" 9set :linked_files, %w{config/database.yml config/secrets.yml} 10set :linked_dirs, %w{bin log tmp/pids tmp/cache sockets bundle public/system public/assets} 11 12set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid" 13 14 set :ssh_options, { verify_host_key: :secure, forward_agent: true } 15 set :rbenv_type, :user 16 set :rbenv_ruby, '2.5.1' 17 set :rbenv_path, '/usr/local/rbenv' 18 set :log_level, :debug

config/deploy/production.rb

ruby

1set :branch, 'master' 2server "ドメイン名", user: "root", roles: %w{app db web} 3 4role :app, %w{root@サーバのIPアドレス} 5role :web, %w{root@サーバのIPアドレス} 6role :db, %w{root@サーバのIPアドレス}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問