使用capistrano部署期间出现ssh问题

时间:2022-04-11 07:25:28

I'm getting permissions errors while trying to deploy my rails app to a friend's server. I'm running rails 3.1.3, ruby-1.9.2-p290, capistrano 2.11.2, Mac OS 10.6.8, and we have ssh keys set up. However, we can't figure out where the permission issues are coming from. We think it might be that capistrano is trying to push the code from the git repo AS THE GIT USER to the deploy directory, or something like that. But this is our first deploy attempt, so we're not sure. Any help would be hugely appreciated!

尝试将rails应用程序部署到朋友的服务器时,我收到了权限错误。我正在运行rails 3.1.3,ruby-1.9.2-p290,capistrano 2.11.2,Mac OS 10.6.8,我们设置了ssh密钥。但是,我们无法确定权限问题的来源。我们认为可能是capistrano试图将代码从git repo作为GIT用户推送到部署目录,或类似的东西。但这是我们的第一次部署尝试,所以我们不确定。任何帮助将非常感谢!

Oh, and here's some more details that my friend told me to specify: appsrv-04.example.ca is the canonical FQDN of the host, and project.example.ca is a CNAME pointing to the A record of appsrv-04.example.ca. The known_hosts file for the git and deploy users contains all of appsrv-04, appsrv-04.example.ca, project, and project.example.ca.

哦,这里有我朋友告诉我指定的更多细节:appsrv-04.example.ca是主机的规范FQDN,而project.example.ca是指向appsrv-04.example的A记录的CNAME .CA。 git和deploy用户的known_hosts文件包含所有appsrv-04,appsrv-04.example.ca,project和project.example.ca。

Below is the output from running cap deploy:update.

以下是运行上限部署:更新的输出。

[user@workstation]~/Code/projectapi $ cap deploy:update
 * executing `deploy:update'
  ** transaction: start
  * executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote ssh://git@appsrv-04.example.ca/usr/local/git_root/projectapi.git master"
Enter passphrase for key '/Users/user/.ssh/id_rsa': 
 command finished in 4478ms
* executing "if [ -d /usr/local/www/sites/project.example.ca/public/shared/cached-copy ]; then cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e71d220f299271522517f7b4f028a9275d53326a && git clean -q -d -x -f; else git clone -q ssh://git@appsrv-04.example.ca/usr/local/git_root/projectapi.git /usr/local/www/sites/project.example.ca/public/shared/cached-copy && cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git checkout -q -b deploy e71d220f299271522517f7b4f028a9275d53326a; fi"
servers: ["project.example.ca"]
Enter passphrase for /Users/user/.ssh/id_dsa: 
[project.example.ca] executing command
 ** [project.example.ca :: err] Permission denied, please try again.
 ** [project.example.ca :: err] Permission denied, please try again.
 ** [project.example.ca :: err] Permission denied (publickey,password).
 ** [project.example.ca :: err] fatal: The remote end hung up unexpectedly
  command finished in 650ms
*** [deploy:update_code] rolling back
 * executing "rm -rf /usr/local/www/sites/project.example.ca/public/releases/20120222225453; true"
servers: ["project.example.ca"]
[project.example.ca] executing command
command finished in 465ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.2-p290@project' -c 'if [ -d /usr/local/www/sites/project.example.ca/public/shared/cached-copy ]; then cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e71d220f299271522517f7b4f028a9275d53326a && git clean -q -d -x -f; else git clone -q ssh://git@appsrv-04.example.ca/usr/local/git_root/projectapi.git /usr/local/www/sites/project.example.ca/public/shared/cached-copy && cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git checkout -q -b deploy e71d220f299271522517f7b4f028a9275d53326a; fi'" on project.example.ca

And here's my deploy file:

这是我的部署文件:

$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) 
require "rvm/capistrano"          

set :application, "Project"

set :scm, "git"
set :repository,  "ssh://git@appsrv-04.example.ca/usr/local/git_root/project.git"
set :user, "deploy"

#set :rvm_bin_path, "/usr/local/rvm/bin"
set :rvm_ruby_string, "1.9.2-p290@project"

ssh_options[:forward_agent] = true

set :branch, "master"

set :deploy_via, :remote_cache

set :deploy_to, "/usr/local/www/sites/project.example.ca/public/"

set :use_sudo, false

set :domain, 'project.example.ca'

role :app, domain
role :web, domain
role :db,  domain, :primary => true

2 个解决方案

#1


14  

You've almost certainly diagnosed this issue correctly; you're trying to check out the github repository as the deploy user and the forwarded key isn't being set up correctly. It looks like you have forward_agent turned on in Capistrano... are you adding your key to your agent so that it gets forwarded correctly?

你几乎肯定会正确地诊断出这个问题;您正在尝试以部署用户身份检出github存储库,并且未正确设置转发的密钥。看起来你在Capistrano中打开了forward_agent ......你是否在你的代理中添加了密钥以便正确转发?

Try doing that with ssh-add ~/.ssh/id-rsa and deploying again.

尝试使用ssh-add~ / .ssh / id-rsa并再次部署。

#2


0  

Problem solved. The virtual host was created by cloning an existing one and changing the IP. I updated the /etc/hosts file to use the new hostname, but apparently not the new IP. So when the deploy user was trying to ssh as the git user... it was failing because there is no git user on the IP it was using.

问题解决了。通过克隆现有虚拟主机并更改IP来创建虚拟主机。我更新了/ etc / hosts文件以使用新的主机名,但显然不是新的IP。因此,当部署用户尝试ssh作为git用户时...它失败了,因为它正在使用的IP上没有git用户。

#1


14  

You've almost certainly diagnosed this issue correctly; you're trying to check out the github repository as the deploy user and the forwarded key isn't being set up correctly. It looks like you have forward_agent turned on in Capistrano... are you adding your key to your agent so that it gets forwarded correctly?

你几乎肯定会正确地诊断出这个问题;您正在尝试以部署用户身份检出github存储库,并且未正确设置转发的密钥。看起来你在Capistrano中打开了forward_agent ......你是否在你的代理中添加了密钥以便正确转发?

Try doing that with ssh-add ~/.ssh/id-rsa and deploying again.

尝试使用ssh-add~ / .ssh / id-rsa并再次部署。

#2


0  

Problem solved. The virtual host was created by cloning an existing one and changing the IP. I updated the /etc/hosts file to use the new hostname, but apparently not the new IP. So when the deploy user was trying to ssh as the git user... it was failing because there is no git user on the IP it was using.

问题解决了。通过克隆现有虚拟主机并更改IP来创建虚拟主机。我更新了/ etc / hosts文件以使用新的主机名,但显然不是新的IP。因此,当部署用户尝试ssh作为git用户时...它失败了,因为它正在使用的IP上没有git用户。