簡體   English   中英

Rails:Capistrano。 被拒絕(公鑰)

[英]Rails : Capistrano. Permisssion Denied(public key)

我一直在尋找一種使用capistrano部署我的應用程序的方法。 我目前正在github和本地服務器上托管一個小型私人倉庫來嘗試部署我的測試。 我遇到了一個問題和下面的錯誤信息。

我做了以下事情

  1. 在服務器上生成一個ssh密鑰並成功添加它以在repo中部署密鑰並進行測試(git@github.com)

  2. 在客戶端生成一個ssh密鑰並成功添加它以在repo中部署密鑰

  3. 設置私有存儲庫。 並且擁有部署權限的帳戶部署者

  4. configed deploy.rb和production rb跟隨模仿許多其他模板。

我仍然無法理解為什么它會給我這樣的錯誤

    DEBUG [a5554d3d] Command: /usr/bin/env chmod +x /tmp/App/git-ssh.sh
    INFO [a5554d3d] Finished in 0.020 seconds with exit status 0 (successful).
    INFO [b1517df1] Running /usr/bin/env git ls-remote --heads git@github.com:aceofw
    ings/App.git as deploy@192.168.1.84
    DEBUG [b1517df1] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/App/git-ssh
    .sh /usr/bin/env git ls-remote --heads git@github.com:aceofwings/App.git )

    DEBUG [b1517df1]        Permission denied (publickey).
    DEBUG [b1517df1]        fatal: Could not read from remote repository.
    DEBUG [b1517df1]
    DEBUG [b1517df1]        Please make sure you have the correct access rights
    DEBUG [b1517df1]        and the repository exists.
    (Backtrace restricted to imported tasks)
    cap aborted!
    SSHKit::Runner::ExecuteError: Exception while executing as deploy@192.168.1.84:
    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.

    SSHKit::Command::Failed: git exit status: 128
    git stdout: Nothing written


Deploy.rb文件

   ###############Deploy.rb##################
# config valid only for current version of Capistrano
lock '3.4.0'

set :repo_url, 'git@github.com:aceofwings/App.git'
set :application, 'App'
set :user, 'deploy'
#set :pty, true
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp



# Default value for linked_dirs is []
# set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')


namespace :deploy do

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end

end


Production.rb

server '192.168.1.84', user: 'deploy', roles: %w{app db web}

#set :stage, :production
 role :app, %w{deploy@192.168.1.84}
 role :web, %w{deploy@192.168.1.84}
 role :db,  %w{deploy@192.168.1.84}


  set :ssh_options, {
    forward_agent: false,
    auth_methods: %w(password),
    password: 'Deploy4Real',
    user: 'deploy'
  }

我遇到了類似的問題。 事實證明SSH代理沒有運行。 我發現了這個看Capistrano文檔: http//capistranorb.com/documentation/getting-started/authentication-and-authorisation/

運行此命令:

$ ssh-add -l

告訴我,我的公鑰沒有添加到代理,所以我不得不添加它:

$ ssh-add

身份添加:/Users/me/.ssh/id_rsa(/Users/me/.ssh/id_rsa)

在此之后,我的Capistrano部署工作。

你應該在production.rb中設置:

forward_agent: true

我與Capistrano 3.4有同樣的問題。 使用Capistrano 3.2.1,它似乎忽略了這個參數。

您可以使用capistrano-ssh-doctor來解決可能的配置問題。

我認為你的capistrano可能在它的git緩存中有一些舊文件,可能來自重命名存儲庫或類似的東西。 嘗試刪除服務器上shared文件夾中的cached-copy文件夾,因此capistrano將再次拉回您的存儲庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM