以下の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アドレス}
あなたの回答
tips
プレビュー