Capistrano Net::SSH::AuthenticationFailed - ruby-on-rails

This is my situation: I have this rails app that I have "capified" and I'm trying to deploy with capistrano onto my Ubuntu cloud server. I have been following this guide -> http://robmclarty.com/blog/how-to-deploy-a-rails-4-app-with-git-and-capistrano
When I run $ cap production deploy, cap aborts and I get the result Net::SSH::AuthenticationFailed.
My guess: My server is not getting access to my bitbucket repo?
Well I have generated an ssh key on my server, added the key in my bitbucket account and also done a git ls-remote git#bitbucket.org:my-username/my-repo.git.
So what am I missing here?
Here's my config/deploy.rb: https://gist.github.com/anonymous/7707266

So my dev computer could not access the production server. It turned out I had put the line server "<server-ip>", user: "depoy-user", roles: %w{web app} in config/deploy.rb. Moving it into config/deploy/production.rb solved my problem. Facepalms, facepalms everywhere.

Related

SSH agent forwarding with Capistrano 3 not working when deploying Rails app

I have the following setup in my deploy.rb
set :application, 'sample_app'
set :repo_url, 'user#123.45.67.100:/home/user/railsapps/sample_app'
set :deploy_to, '/var/www/sample_app'
set :user, "user"
set :ssh_options, { :forward_agent => true }
and my deploy/production.rb file:
set :stage, :production
server '123.45.67.200', user: 'user', roles: %w{app db web}
I get the following error when I run cap production deploy:check
DEBUG [] ssh: connect to host 123.45.67.100 port 22: Connection timed out
DEBUG [] 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 user#123.45.67.200: git exit status: 128
git stdout: Nothing written
git stderr: ssh: connect to host 123.45.67.200 port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
In one of the lines, I see that it tries to access the repository as user#123.45.67.200, which is the deployment user for the production server:
INFO [] Running /usr/bin/env git ls-remote --heads user#123.45.67.100:/home/user/railsapps/sample_app as user#123.45.67.200
Shouldn't it be saying that it's connecting as the local user with the local ssh keys? Is Capistrano logging into the production server and then pulling code from the repository? If it is, is there a way to make it push code from the repository to the production server?
It appears that your Git URL is not valid. You can test this by connecting to the remote system (user#123.45.67.200) and try to hit the remote Git repo with a simple git ls-remote --heads which will prove connectivity.
git ls-remote --heads user#123.45.67.100:/home/user/railsapps/sample_app
I suspect that you might need .git appended to your URL (user#123.45.67.100:/home/user/railsapps/sample_app.git) but that really depends on how you have your remote repo set up.
Git does use SSH to connect but it doesn't explicitly show that in the Capistrano output. All you will see are the explicit git commands.
Alternatively, if you are expecting to use agent forwarding then you might be experiencing an issue with your ssh forwarding config, either local or remote. You can test that by checking your local machine then connecting to a remote machine and seeing if your identity was forwarded. You would do that like this:
local-host$ ssh-add -l
local-host$ ssh user#remote-host
remote-host$ ssh-add -l
If you see output like:
Error connecting to agent: No such file or directory
or:
Could not open a connection to your authentication agent.
or:
The agent has no identities.
Then you need to sort out that issue before Capistrano will work as expected.
You can checkout this write up "Using ssh-agent with ssh" to help with SSH config.
Capistrano will log into the server, and then from the server pull down the code from your VCS.
There are usually two ways of authenticating this:
ssh-agent forwarding which will give the remote session access to your developer key, or
deploy keys which will give the server user's key access to your code.
The second half of this documentation page describes the way Git works with Capistrano: http://capistranorb.com/documentation/getting-started/cold-start/
From the errors you have posted, you probably need to set up one or the other of the above options.

Intercity chef-repo Capistrano asking for deploy password

I have set up a vps everything according to the https://github.com/intercity/chef-repo instructions. I have set up Capistrano but when i try cap production deploy:check
it keeps asking for deploy password. But i don't have one because it is generated through the intercity node. I have the public key of my server in the node file.
Check that you can log in via normal SSH manually. Guessing you didn't get the SSH keys installed correctly.

Capistrano 3 SSHKit::Runner::ExecuteError: Exception while executing on host [hostname ]agent could not sign data with requested identity

I'm getting the following error while deploying my rails app to an ubuntu server, I have correctly setup ssh keys and I can ssh to the server but I'm getting the following when I try to do
cap production deploy
This is the error message
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxxxxx.xxxxxxx.xxx: agent could not sign data with requested identity
I can't figure out what I am doing wrong since I had previously deployed and I just need to update my app to changes I have made. I have not changed my deploy.rb, Capfile or deploy/production.rb files since I last deployed
I solved a similar issue by just issuing ssh-add. It seems that my current environment hasn't properly picked up the keys and readding them fixed the issue.
I had the same error.
ssh-copy-id user#ipaddress
Helped me to solve this.
I had the same issue but in my case I had to delete file .ssh/known_hosts from my local machine.
After upgrading Rails from 4.1.x to 4.2, I started getting similar errors when trying to bundle. I fixed it by removing the shared bundle directory. Here's the steps I took:
SHH into the server
cd /my/app/shared/bundle/ruby
rm -rf 2.1.0 or whatever "version" directory is there
Re run the deploy cap production deploy
You may, at this point, hit a memory snag (I did while deploying to a DigitalOcean droplet). The fix for that is to create and enable a swap file on the droplet.

Connect to github from linode with Capistrano deploy gives permission denied to public key

This is my first time using linode and uploading a Rails app to a VPS, so I might of skipped something obvious.
I followed two tutorials
Ryan Bates video to deploying to a vps
and
David's answer on Stackoverflow
I am at the point where I want to deploy my rails app on Linode (Ubuntu 13.10)
When I execute the command bundle exec cap deploy:update
I get the errors that Linode cannot connect to github due to a public key
user:my-app User$ bundle exec cap deploy:update
* 2014-02-12 17:19:46 executing `deploy:update'
** transaction: start
* 2014-02-12 17:19:46 executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#github.com:user/my-app.git master"
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
*** [deploy:update_code] rolling back
* executing "rm -rf /home/user/apps/my-app/releases/20140212091953; true"
servers: ["XXX.XXX.XX.XX"]
[XXX.XXX.XX.XX] executing command
command finished in 4607ms
Command git ls-remote git#github.com:user/my-app.git master returned status code pid 1529 exit 128
On my local machine I have no problem to commit and push my app on Github and I have RSA Keys on my local computer. It just asks me to login with my username and password each time I push my app.
On linode from the shell, I can connect to github by using ssh -vT git#github.com. I do have the RSA keys on the linode server and I added the ssh-agent using ssh-add
my deploy.rb
set :application, "my-app"
set :user, "user"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :keep_releases, 3
default_run_options[:pty] = true
set :scm, :git
set :repository, "git#github.com:user/#{application}.git"
set :ssh_options, { :forward_agent => true }
# ssh_options[:forward_agent] = true
set :branch, "master"
I am a bit at a loss.
EDIT: I have a private repository
I just moved from Linux to Mac OSx. Thus, I have imported whole .ssh folder from linux to mac. While moving from linux to linux it worked, but to make it work on Mac, I had also to run:
ssh-add
That's the whole fix ;) See http://peteoliveira.com/deploying-with-capistrano-3-failing-permission-denied-publickey/ for more info.
So I found the solution to this github connection. I actually have another problem with the deployment where the bundle install fails. Anyways here is what I learned and I hope it will help others.
What you need to know:
With Capistrano when you wish to push your public or private Github
repository onto your VPS server, you need to make sure that BOTH your
server and your computer has an SSH access with Github.
Even if you can git push origin master it doesn't mean you have SSH
access with Github. Here is how you troubleshoot:
A) Make sure you can SSH access from your computer
Make sure you have Git installed on your machine Set up Git
tutorial
Make sure that you have an SSH Key on your local machine (with Linux
or Mac)
cd ~/.ssh then
ls -a
and look for the files id_rsa and id_rsa.pub
If you don't have these rsa files, follow this tutorial
Generating SSH keys
Copy your SSH key
pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
Login with your browser on http://www.github.com and go to
your_username -> edit profile -> settings -> ssh keys
https://github.com/settings/ssh. Click the button Add keys, add the name that identifies your comptuter and paste the key code that you previously copied.
Make sure you have SSH Agent on. In Terminal type
ssh-add #enter a passphrase if you want to (recommended)
Test if you can SSH with Github
ssh git#github.com
The first time it may ask you to accept the connection.
You should get the following response
PTY allocation request failed on channel 0
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
You can also make sure that your id_rsa is properly found by running
ssh -vT git#github.com
# make sure that this line is not -1 (it means it couldn't find the file)
=> debug1: identity file /Users/YOUR_USERNAME/.ssh/id_rsa type 1
Now you shouldn't have permission denied (Public Key)
B) Make sure you can SSH access from your server
Run ssh root#your_server_ip_address if you didn't setup a user on your server or ssh username#your_server_ip_address. You will then be within the server shell and you want to repeat the same process for your computer.
NOTE: The server SSH Keys will be different than your computer. That means that on Github you need to add 2 SSH Keys, one for your computer and one for your server. That is why you need to repeat the process on both machines. Also to keep it simple, do not try to have more than one SSH Key on each machine.
NOTE 2: In your server after you generated your SSH key, to copy it run the command cat ~/.ssh/id_rsa.pub
Once both your computer and the server are accepted on Github, then you can update your rails app using capistrano and your Github repository. Yay!

unable to use capistrano -- prompted for password i am not sure of

ruby on my development machine:ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
capistrano on my development machine: Capistrano v2.5.5
OS on development machine: ubuntu 10.04 desktop edition
server is Amazon web service instance running on ubuntu server 64 bit 10.04
ruby on server: ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
Capistrano v2.5.5
deploy.rb: http://gist.github.com/643504
what i want to do:
i want to be able to deploy on 2 different folders in /var/www in my server.
1 folder is for example.com
1 folder is for example.biz
the .biz is staging and .com is production.
i will also have 2 different databases. 1 for staging 1 for production
i want to use capistrano to deploy code on my production folder AND staging folder.
for deploying staging folder, i want to be able to
1) do a git pull at the server for the staging folder ONLY.
2) run a bash script that will restore the staging database. script is written and placed inside the staging folder.
for production folder, i just want to be able to do a git pull at the server for production folder ONLY.
IMMEDIATE issues:
1) right now as i test my code i am unable to do a git pull at the server for staging folder ONLY.
i ran this command in my devt machine.
cap staging deploy
i get prompted for a password i am not sure of.
screenshot of what i saw
http://picasaweb.google.com/kimcity/Screenshots#5531588545516293762
Please help
I have tried this capistrano password prompt
and i did the following in my ~/.ssh
vi config
inserted the following text
Host production
Hostname example.com
User username_of_server
ForwardAgent yes
Host staging
Hostname example.biz
User username_of_server
ForwardAgent yes
Host *
ForwardAgent no
Still does not work for me.
Potential issues:
1) if i make any mistakes in my deploy.rb that may cause other issues further down the road towards what i want to achieve, please let me know.
assuming installation is not an issue etc,
assuming that you want to have the following setup,
and that you want to do it this way:
run "cap production deploy" from your laptop and have your server git pull the latest code from a public repository like github.com or projectlocker.com
the key thing is that you need to create a user account ON YOUR SERVER that is meant for deployment.
let us call this user account 'deploy' without the quotes.
1) make sure that 'deploy' has the public key of your laptop. (assuming you already have created a key pair for your laptop)
the public key of your laptop is a long sequence of text that should be in /home/deploy/.ssh/authorized_keys
create the folders or file if they do not exist.
2) check that you can ssh into the server using deploy#server from your laptop. if this works, it means that you have done 1) correctly.
3) generate keypair for 'deploy' at your server machine.
4) go to github.com or projectlocker and place the public key of the keypair in 3) over at the website.
5) go to your working folder at server. Do a git init if you did not already have a .git inside that folder. run git pull git-abc#github.com:abc.git or whatever your git repo url is.
6) if you succeed to pull your latest code from the public repo at github or projectlocker, steps 3 and 4 were correctly done.
7) now ensure that you have the following in your deploy.rb
# set server user account responsible
set :user, "deploy"
# Deploy via a remote repository cache. In git's case, it
# does a "git fetch" on the remote cache before moving it into place
# can change this to :copy but apparently :remote_cache is faster
set :deploy_via, :remote_cache
8) run "cap production deploy:setup" because you are going to deploy for the very first time.
9) run "cap production deploy" subsequently.

Resources