簡體   English   中英

Capistrano 3 部署無法連接到 GitHub - 權限被拒絕(公鑰)

[英]Capistrano 3 deploy fails connecting to GitHub - Permission denied (publickey)

我使用 Capistrano v3 和 capistrano/symfony gem 設置了以下部署腳本。 我正在使用 Ubuntu 14.4 部署到 AWS EC2 實例我正在連接從 AWS 下載的 .pem 文件。 我的 deploy.rb 中有以下內容

set :pty, true

set :ssh_options, {
  user: 'ubuntu',
  keys: ['/Users/myuser/Sites/Myproject.pem'],
  forward_agent: true,
  auth_methods: ["publickey"]
}

部署時

bundle exec cap staging deploy --trace

腳本連接正常,但失敗了

INFO [4fd1b02c] Running /usr/bin/env git ls-remote --heads git@github.com:MyName/Myproject.git as ubuntu@ec2-00-000-000-000.eu-west-1.compute.amazonaws.com
DEBUG [4fd1b02c] Command: ( SYMFONY_ENV=prod GIT_ASKPASS=/bin/echo GIT_SSH=/var/www/tmp/myproject/git-ssh.sh /usr/bin/env git ls-remote --heads git@github.com:MyName/Myproject.git )

DEBUG [4fd1b02c]    Permission denied (publickey).
DEBUG [4fd1b02c]    
DEBUG [4fd1b02c]    fatal: Could not read from remote repository.
DEBUG [4fd1b02c]    
DEBUG [4fd1b02c]    
DEBUG [4fd1b02c]    Please make sure you have the correct access rights
DEBUG [4fd1b02c]    
DEBUG [4fd1b02c]    and the repository exists.
DEBUG [4fd1b02c] 

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ubuntu@ec2-00-000-000-000.eu-west-1.compute.amazonaws.com: git exit status: 128
git stdout: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
git stderr: Nothing written

我不知道為什么 forward_agent 不起作用?

我一直在嘗試遵循本指南 - https://developer.github.com/guides/using-ssh-agent-forwarding/#testing-ssh-agent-forwarding

但是當我遇到這個

echo "$SSH_AUTH_SOCK"

它打印一個空行。

另外,如果我在服務器上運行它,它會說找不到命令

sshd_config

仔細檢查運行 Capistrano 的用戶是否運行了ssh-agent並且ssh-add了相關的密鑰。

這里有一些很好的指南:

https://developer.github.com/guides/using-ssh-agent-forwarding/

http://mah.everybody.org/docs/ssh

我的問題的解決方案是兩件事。 首先,我必須像這樣在腳本中轉發我的 id_rsa:

set :ssh_options, {
  user: 'ubuntu',
  keys: ['~/.ssh/id_rsa'],
  forward_agent: true,
  auth_methods: ["publickey"]
}

我將我的 id_rsa.pub 密鑰放在服務器上,以便我可以使用與轉發相同的密鑰 ssh 進入服務器。

我必須做的第二件事是使用 /tmp 設置權限

chmod 1777 /tmp

我在上限運行期間遇到了類似的問題“ $ bundle exec cap test deploy

Error : 
git stdout: Nothing written
git stderr: Warning: Permanently added the RSA host key for IP address 'xxxxxxxxx' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

對於這種情況,我們需要使用 ssh 密鑰對 github 帳戶進行身份驗證

導航到 github -> 設置 -> SSH 和 GPG 密鑰(部分)-> 添加“新 SSh 密鑰”,復制您的公鑰( $ ssh-keygen #generate new key ))並粘貼密鑰輸入字段。 添加密鑰后,使用此命令“ $ ssh -T git@github.com ”檢查身份驗證。 它將顯示以下輸出

Hi <xxxxxxxx>! You've successfully authenticated, but GitHub does not provide shell access.

現在它工作正常!

  1. 添加下一個 gems 結束包
gem 'capistrano', require: false

gem 'capistrano-bundler', require: false

gem 'capistrano-rails', require: false

gem 'capistrano-rvm', require: false

gem 'capistrano-sidekiq', require: false
  1. $ cap -T

您會看到所有命令的說明。

  1. 從您的變體環境結束執行命令。

如果檢查生產

$ cap production deploy:check

如果分期

$ cap staging deploy:check

暫無
暫無

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

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