Authentication failed for user when deploying to Amazon EC2 - ruby-on-rails

I am trying to run cap production deploy under my project folder using Capistrano 3. I am able to ssh into my production server using the pem as login credential. But when I run cap production deploy, I get the following message:
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host cityspade.com: Authentication failed for user ec2-user#cityspade.com
The EC2 server has already allowed my IP for SSH connecting. No idea how to fix this issue.

Capistrano uses your default available keys to login. You might need to set up ssh-agent and add the pem to the available keys.

Related

AutoDeploy rails app via jenkins and capistrano

As first steps I have configured AWS EC2 instance with Ubuntu 16.04 and configured Capistrano for deploy from local to this AWS EC2 instance.
Now I am trying to make autodeploy rails app from GitHub to this Ubuntu Server (AWS EC2) via Jenkins and Capistrano. Note: I am creating autodeploy for the first time.
My rails app (production) and Jenkins are on the same Amazon EC2 instance.
When Jenkins task starts, it clones repo to the jenkins workspace, install gems and then execute: cap production deploy
But now I can“t check that the Capistrano was configured correctly for deploy to another folder of the same server, because when cap production deploy executes I get this error:
Net::SSH::AuthenticationFailed: Authentication failed for user jenkins#
I tried to create ssh-key for user jenkins and add it to ubuntu user (default non-root sudo user) by:
ssh-keygen
ssh-copy-id ubuntu#127.0.0.1
and always get permission denied error.
Does anybody have any suggestions?
Thank you in advance
capistrano version 3.11
You can add jenkin user's public-key in the authorized_keys file of ubuntu user. You can find it at /home/ubuntu/.ssh/authorized_keys.
However, In my opinion, you should migrate the jenkins runner to a separate server.
You can create a VPC group, and put both the servers, production and jenkins runner in that single VPC, and expose ssh port in the same VPC, so that no one outside can access it.
Then add the public key of thejenkins server to the production server as I have explained above.

Deploy Ruby on Rails 5 to AWS Elastic Beanstalk

I'm attempting to deploy a Ruby on Rails application to AWS Elastic Beanstalk using the aws cli and the elasticbeanstalk cli installed via homebrew.
I've created my application in Elastic Beanstalk via the eb init command and then using the following command to attempt to build my production environment
eb create production -db -db.engine postgres
This command succeeds in building some of the resources required, but fails on the second security group it tries to build, the one which is required for the RDS instance (postgresql). The output from the failure is as follows:
Printing Status:
INFO: createEnvironment is starting.
INFO: Using elasticbeanstalk-us-east-1-060304732879 as Amazon S3 storage bucket for environment data.
INFO: Created security group named: sg-6df63b27
INFO: Created load balancer named: awseb-e-v-AWSEBLoa-SNYOVF7XI1O
INFO: Created security group named: awseb-e-vfpiydbe4p-stack-AWSEBSecurityGroup-7CUYEFRLYW20
INFO: Created Auto Scaling launch configuration named: awseb-e-vfpiydbe4p-stack-AWSEBAutoScalingLaunchConfiguration-PBAKQ91A7F1C
ERROR: Stack named 'awseb-e-vfpiydbe4p-stack' aborted operation. Current state: 'CREATE_FAILED' Reason: The following resource(s) failed to create: [AWSEBRDSDBSecurityGroup].
ERROR: Creating RDS database security group named: awseb-e-vfpiydbe4p-stack-awsebrdsdbsecuritygroup-1er5fh5espelw failed Reason: Either the resource does not exist, or you do not have the required permissions.
INFO: Launched environment: production. However, there were issues during launch. See event log for details.
Has anyone else encountered this issue? I've double checked (and also reset) my AWS credentials and ensured that the one and only use I have set up in my IAM console is set to AdministratorAccess and I'm using the AWS Access and Secret Key set up for that user.
Any assistance would be greatly appreciated!

Capitrano authentication fails with Git bash on Windows

I configured capitrano to deploy a Rails app from Git bash on Windows. I created one rsa key to connect to the remote server with the user deploy and another rsa key to connect to bitbucket with my account.
Before deploying I set up the ssh-agent with both keys.
When deploying I have an authentication failed (publickey error) nevertheless when I try to ssh deploy#myserver.com it works and from inside my server if I try git -T git://bitbucket.org it connects and show me my username.
How can I debug this issue?
The issue was that the ssh client used by capitrano doesn't handle ssh-agent on Windows. The solution was to use Pageant the agent of the putty project but before importing keys to pageant they have to be converted to the ppk format by puttykeygen

Nginx and Unicorn Set up Not sure what I am doing

This is my first time setting up nginx and unicorn, someone directed me to this tutorial:
http://teohm.github.io/blog/2013/04/17/chef-cookbooks-for-busy-ruby-developers/
I have a general understanding of what I am doing but I am stuck on this section:
Install chef-solo on remote server
when I run
bundle exec knife solo prepare testbox
I get
ERROR: Network Error: getaddrinfo: nodename nor servname provided, or not known
Check your knife configuration and network settings
I am guessing that I don't have ~/.ssh/config
this is from the example
Host testbox
User ubuntu
Hostname ec2-51-221-13-121.ap-southeast-1.compute.amazonaws.com
IdentityFile ~/.ssh/testbox_ec2.pem
am I suppose to make a config file in .ssh? should I switch to ubuntu?
I am using heroku, how should I find my hostname? what is the pem file in ssh?
I've never used knife... It might be worth checking out this this blog post about setting up Capistrano, Nginx, and Unicorn - I've always found Capistrano to be a good deployment app (and there's lots of support for it, especially on SO).
On Heroku, you don't deploy as you would with Capistrano or any other deployment utility - you simply push to a branch on your Heroku server. See: https://devcenter.heroku.com/articles/git for how to deploy on Heroku using Git.

How to provide password for Capistrano rails 3.1 app deployment to aws ec2 ubuntu server?

We are trying to deploy a rails 3.1 app on a aws ec2 instance running ubuntu 12.04. With cap deploy, However, we are stuck with the password hint. There is only private key in aws ecs login and there is no password. How can we pass the ssh login for ec2 deployment?
Thanks so much.
This is what I did to solve this scenario:
On the local machine, generate a key using e.g. ssh-keygen. Keep the standard location to not overcomplicate things, i.e. keyfiles should be ~/.ssh/id_rsa and id_rsa.pub; SKIP THIS STEP IF YOU ALREADY HAVE KEYS IN .ssh
Copy the content of the id_rsa.pub file
SSH into the EC2 instance using your .pem keyfile
Paste the content of your local id_rsa.pub into /home/[YOUR_EC2_USER]/.ssh/authorized_keys
You should now be able to use capistrano for your deployment.

Resources