Capifony error during deployment (OpenSSL::PKey::PKeyError: not a public key "/var/www/.ssh/id_rsa.pub") - capistrano

I keep getting this error (OpenSSL::PKey::PKeyError: not a public key "/var/www/.ssh/id_rsa.pub")
Thanks in advance.
My deploy.rb looks like this:
set :application, "goom"
set :domain, "goom#bloom.com"
set :deploy_to, "/var/www/goom"
#set :app_path, "app"
set :repository, "/var/www/goom/.git"
set :scm, :git
set :deploy_via, :copy
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, $
set :model_manager, "doctrine"
# Or: `propel`
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your$
role :db, domain, :primary => true # This is where Rails migratio$

It turnes out that it is a format issue. Originally my public key had the following format:
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20101206"
AAAAB3NzaC1yc2EAAAABJQAAAQB80B66jlf+Xo3E0d6TJdojKB1mkblUCjyCaOA1
p2GpvQr+TjtCugdmh9069ybWcJCaRcvJu12pz/0iO8H0Ar/f3AiULaj6VHF9rdkA
qp+k+Ih0ep204VENqgobGfDOKfBcd2o9P1zdbCuie28tGSxoQMZNVVPMXPgl80HQ
v8+dqL4YDEvsViOMa/A1pxlvw74XwU6jzaVM+4u2ysKu0xEJzSUR4wT4s7f0zr3G
FNZDlj0vmuyggo9/3BIgtAQC9IcALqT5Jf3V5iN03+8uPUJVuy+XvIJoZJo5fnrT
zXzDBdUmjJNt+zTYsX3/fHQZOxokHPiBQQ5OTL+NW1Uscukv
---- END SSH2 PUBLIC KEY ----
Reformatting it to the following did the trick:
ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQB80B66jlf+Xo3E0d6TJdojKB1mkblUCjyCaOA1p2GpvQr+TjtCugdmh9069ybWcJCaRcvJu12pz/0iO8H0Ar/f3AiULaj6VHF9rdkAqp+k+Ih0ep204VENqgobGfDOKfBcd2o9P1zdbCuie28tGSxoQMZNVVPMXPgl80HQv8+dqL4YDEvsViOMa/A1pxlvw74XwU6jzaVM+4u2ysKu0xEJzSUR4wT4s7f0zr3GFNZDlj0vmuyggo9/3BIgtAQC9IcALqT5Jf3V5iN03+8uPUJVuy+XvIJoZJo5fnrTzXzDBdUmjJNt+zTYsX3/fHQZOxokHPiBQQ5OTL+NW1Uscukv

I figured it out.
As you can see in the first line:
(OpenSSL::PKey::PKeyError: not a public key "/var/www/.ssh/id_rsa.pub")
Ruby claims to be looking in the /var/www/.ssh folder... it's not.
It's actually defaulting... for whatever insane reason... to /var/www/ So all I did was copy id_rsa and id_rsa.pub to /var/www and it ran just fine.
Never actually got it to DEPLOY mind you... (I eventually used Git for that)... but I did get past this error!

Related

How can I solve Permission denied on deploying app?

I have setup an app to deploy to my site that is hosted on Digital Ocean CentOS 6 server and I am using Capistrano to deploy the app from my development machine. I have got a repo setup that I push to and that my Capistrano config references when I do cap development deploy.
The issue I am having is that it throws this error:
[a7406f5e] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/PopupHub/git-ssh.sh /usr/bin/env git ls-remote git#repo-url-is-here/popup-hub.git )
DEBUG [a7406f5e] Permission denied (publickey).
DEBUG [a7406f5e] fatal: The remote end hung up unexpectedly
In capfile I have got this:
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
#
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/sitemap_generator'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
In my config/deploy.rb I have:
lock '3.1.0'
server "0.0.0.0.0"
set :application, "NameOfApp"
set :scm, "git"
set :repo_url, "git#the-repo-url-is-here/popup-hub.git"
# set :scm_passphrase, ""
# set :user, "deploy"
# files we want symlinking to specific entries in shared.
set :linked_files, %w{config/database.yml}
# dirs we want symlinking to shared
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
SSHKit.config.command_map[:rake] = "bundle exec rake" #8
SSHKit.config.command_map[:rails] = "bundle exec rails"
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
set :keep_releases, 20
namespace :deploy do
desc 'Restart passenger without service interruption (keep requests in a queue while restarting)'
task :restart do
on roles(:app) do
execute :touch, release_path.join('tmp/restart.txt')
unless execute :curl, '-s -k --location localhost | grep "Pop" > /dev/null'
exit 1
end
end
end
after :finishing, "deploy:cleanup"
after :finishing, "deploy:sitemap:refresh"
end
after "deploy", "deploy:migrate"
after 'deploy:publishing', 'deploy:restart'
# deploy:sitemap:create #Create sitemaps without pinging search engines
# deploy:sitemap:refresh #Create sitemaps and ping search engines
# deploy:sitemap:clean #Clean up sitemaps in the sitemap path
# start new deploy.rb stuff for the beanstalk repo
Then in my config/development.rb I have got:
set :stage, :development
set :ssh_options, {
forward_agent: true,
password: 'thepassword',
user: 'deployer',
}
server "0.0.0.0", user: "deployer", roles: %w{web app db}
set :deploy_to, "/home/deployer/development"
set :rails_env, 'development' # If the environment differs from the stage name
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
When I push in bash cap development deploy the error further up happens.
Can anyone tell me why this is happening? I have carried out everything fine up to now and I have this setup on another Digital Ocean droplet.
Thanks,
I think you have not ssh access to your remote server using you local system's ssh keys.
If you don't have ssh keys on local system, generate:
ssh-keygen -t rsa
Upload your local keys to remote server:
cat ~/.ssh/id_rsa.pub | ssh user#hostname 'cat >> .ssh/authorized_keys'
Source: HowToGeek.com
You need to set up your SSH key in Digital Ocean

Chef running git clone results in host key verification error

I am using Chef, invoked by Capistrano.
There is a directive to clone a repository using git.
git node['rails']['rails_root'] do
repository "git#myrepo.com:/myproj.git"
reference "master"
action :sync
user node['rails']['rails_user']
group node['rails']['rails_group']
end
When it gets to this point, I get:
** [out :: 10.1.1.1] STDERR: Host key verification failed.
So, I need to add a "known_hosts" entry. No problem. But to which user? The core of my problem is that I have no idea which user is executing what commands, and if they are invoking sudo, etc.
I've run keyscan to populate the known_hosts of root, and the user I ssh in as, to no avail.
Note, this git repo is read-protected, and requires ssh key access.
Another way to solve https://github.com/opscode-cookbooks/ssh_known_hosts
this worked for me
You can use an ssh wrapper approach. Look here for details.
Briefly do the following steps
First, create a file in the cookbooks/COOKBOOK_NAME/files/default directory that is named wrap-ssh4git.sh and which contains the following:
#!/usr/bin/env bash
/usr/bin/env ssh -o "StrictHostKeyChecking=no" $1 $2
Then, use the following block for your deployment:
directory "/tmp/private_code/.ssh" do
owner "ubuntu"
recursive true
end
cookbook_file "/tmp/private_code/wrap-ssh4git.sh" do
source "wrap-ssh4git.sh"
owner "ubuntu"
mode 00700
end
deploy "private_repo" do
repo "git#github.com:acctname/private-repo.git"
user "ubuntu"
deploy_to "/tmp/private_code"
action :deploy
ssh_wrapper "/tmp/private_code/wrap-ssh4git.sh"
end
The git repository will be cloned as user node['rails']['rails_user'] (via https://docs.chef.io/resource_git.html) - I assume that users known_hosts file is the one you have to modify.
I have resolved this issue as below
_home_dir = nil
node['etc']['passwd'].each do |user, data|
if user.eql? node['jenkins']['username']
_home_dir = data['dir']
end
end
key_config ="Host *\n\tStrictHostKeyChecking no\n"
file "#{_home_dir}/.ssh/config" do
owner node['jenkins']['username']
group node['jenkins']['username']
mode "0600"
content key_config
end

Capifony & Symfony 2 error: php bin/vendors install --reinstall

I have a big problem.
I had a configuration which worked properly till today.
I don't know why I have now this error
*** [err :: server.com] Could not open input file: bin/vendors
command finished in 312ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/server/deploy/releases/20120301143822; true"
servers: ["server.com"]
[server.com] executing command
command finished in 208ms
failed: "sh -c 'cd /home/server/deploy/releases/20120301143822 && php bin/vendors install --reinstall'" on server.com
I precise that I deploy my local work to production
here is my deploy file
set :application, "MyApp"
set :deploy_to, "/home/server/deploy"
set :serverName, "myServer.com" # The server's hostname
set :domain, "server.com"
set :scm, :git
set :repository, "file:///Applications/MAMP/htdocs/localWorkDev"
set :deploy_via, :rsync_with_remote_cache
role :web, domain
role :app, domain
role :db, domain, :primary => true
set :use_sudo, false
set :keep_releases, 3
set :user, "root"
set :shared_files, ["app/config/parameters.ini"]
set :shared_children, [app_path + "/logs", web_path + "/uploads", "vendor"]
set :update_vendors, true
Please help me
Thanks
Sam
ALL is right now. I have just done a
php bin/vendors install --reinstall
and now it works.
In my case, it was very important to add --reinstall command.
Hope it would be usefull
Sam

Bundle install failing when deploying a Rails 3 app to Dreamhost with Capistrano

I am trying to deploy a locally working Rails 3 app to Dreamhost with Capistrano.
When I run 'cap deploy -v' in my local app root I get so far before it chokes on 'bundle install'. The following is the end of the error message:
** transaction: start **
[abunchofletters.co.uk :: out] my_username#abunchofletters.co.uk's password:
Password: **
[abunchofletters.co.uk :: out] **
[abunchofletters.co.uk :: out] HEAD is now at 62f9cdb Initial deploy to Dreamhost
** [out :: abunchofletters.co.uk] sh: bundle: command not found
* [deploy:update_code] rolling back
failed: "sh -c 'bundle install --gemfile /home/my_username/abunchofletters.co.uk/releases/20110111100145/Gemfile --path /home/my_username/abunchofletters.co.uk/shared/bundle --deployment --quiet --without development test'" on abunchofletters.co.uk
Yet when I SSH into my server, and check the gem list, bundler 1.0.7 is shown to be installed [also running Ruby 1.8.7, Rails 3.0.3, RubyGems 1.3.6]. This is my first experience with deploying a Rails app as well as Capistrano so I'm close to clueless but I'd guess some path or variable is not set correctly.
Here's my deploy.rb [created from following http://railstips.org/blog/archives/2008/12/14/deploying-rails-on-dreamhost-with-passenger/ so could be outdated]:
require "bundler/capistrano" # http://gembundler.com/deploying.html
default_run_options[:pty] = true
# be sure to change these
set :user, 'my_username'
set :domain, 'abunchofletters.co.uk'
set :application, 'abunchofletters'
# the rest should be good
set :repository, "#{user}##{domain}:git/#{application}.git"
set :deploy_to, "/home/#{user}/#{domain}"
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
server domain, :app, :web
role :db, domain, :primary => true
namespace :deploy do
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
Any ideas how to progress? If there's any more info you need just prompt me and I'll supply it.
I'm not too satisfied with the solution I came up with, but it got the deploy to work and bundler to update.
Here's my updated deploy.rb:
#require "bundler/capistrano"
default_run_options[:pty] = true
# be sure to change these
set :user, 'futureproof'
set :domain, 'abunchofletters.co.uk'
set :application, 'abunchofletters'
# the rest should be good
set :repository, "#{user}##{domain}:git/#{application}.git"
set :deploy_to, "/home/#{user}/#{domain}"
set :deploy_via, :remote_cache
set :shared_path, "/home/#{user}/.gems"
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
server domain, :app, :web
role :db, domain, :primary => true
namespace :deploy do
desc "expand the gems"
task :gems, :roles => :web, :except => { :no_release => true } do
run "cd #{current_path}; #{shared_path}/bin/bundle unlock"
run "cd #{current_path}; nice -19 #{shared_path}/bin/bundle install vendor/" # nice -19 is very important otherwise DH will kill the process!
run "cd #{current_path}; #{shared_path}/bin/bundle lock"
end
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
The :gems task was seen here: http://grigio.org/deploy_rails_3_passenger_apache_dreamhost, though the bundle lock/unlock are deprecated now. Might be able to simply replace with bundle install/update, but deprecated will do for tonight.

Capistrano remote authentication problem

I'm trying to deploy to a slicehost slice using this config/deploy/production.rb file. I'm clueless & haven't used capistrano before now. Here are the steps I followed. Sorry but I'm completely new to capistrano. It keeps asking for my password (have set up passwordless SSH), and throwing this error:
(SocketError: getaddrinfo: Name or service not known)
connection failed for: ---------.com (Net::SSH::AuthenticationFailed: -----)
First, it's a 'bort' app http://github.com/fudgestudios/bort/tree/master
Second, I used the ubuntu-machine gem, detailed here:
http://suitmymind.github.com/ubuntu-machine/#screencast
config/deploy/production.rb
#############################################################
# Application
#############################################################
set :application, "---------------"
set :deploy_to, "/var/www/#{application}"
#############################################################
# Settings
#############################################################
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :use_sudo, true
set :scm_verbose, true
set :rails_env, "production"
#############################################################
# Servers
#############################################################
set :user, "----------"
set :domain, "--------------------------"
server domain, :app, :web
role :db, domain, :primary => true
#############################################################
# Git
#############################################################
set :scm, :git
set :branch, "master"
set :scm_user, '---------'
set :scm_passphrase, "----------"
set :repository, "git#github.com:--------/----------.git"
set :deploy_via, :remote_cache
#############################################################
# Passenger
#############################################################
namespace :deploy do
desc "Create the database yaml file"
task :after_update_code do
db_config = <<-EOF
production:
adapter: mysql
encoding: utf8
username: root
password: ------------
database: ------------_production
host: localhost
EOF
put db_config, "#{release_path}/config/database.yml"
#########################################################
# Uncomment the following to symlink an uploads directory.
# Just change the paths to whatever you need.
#########################################################
desc "Symlink the assets directories"
task :before_symlink do
run "mkdir -p #{shared_path}/assets"
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
end
end
# Restart passenger on deploy
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end
end
end
I think the problem would be either
It can't resolve your hostname
You typo wrong domain value
Just in case, have you tried to set the domain value to be your server's IP address instead?
"SocketError: getaddrinfo: Name or service not known" implies some sort of problem resolving or connecting to the remote host. Have you checked that you can connect manually?
One way to start debugging cap scripts is to perform each step of the process yourself. You can copy the statements directly from the verbose cap output. That should help isolate the problem, in this case, where the connection problem is (slicehost?, github?, both?).