Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Net::SSH::AuthenticationFailed: Authentication failed for user

Local Computer Username: Christopher

Ubuntu Server Username: my_app_name

I have followed the Digital Ocean documentation to set up an Ubuntu 16.04 server with Ruby on Rails and is my first time doing so, though when I get to cap production deploy:initial the console returns Net::SSH::AuthenticationFailed: Authentication failed for user [email protected] even though I am able to ssh without a problem into my root and user accounts.

I followed these instructions:

How to connect your droplet with Digital Ocean https://www.digitalocean.com/community/tutorials/how-to-connect-to-your-droplet-with-ssh

Initial Server Setup with Ubuntu 16.04
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04

I generated an ssh public/private key pair on my local computer using:

ssh-keygen -t rsa

I added the public key from my local computer to the servers ~/.ssh/authorized_keys file. I was then able to ssh into my root and user accounts.

I then followed these instructions:

Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma

I generated another ssh key, this time on the server and added the public key to my github's deploy keys list. I was then able to successfully clone my repo through ssh.

I run the following commands:

cat ~/.ssh/id_rsa.pub | ssh -p your_port_num deploy@your_server_ip 'cat >> ~/.ssh/authorized_keys'

cap production deploy:initial

And get back:

Net::SSH::AuthenticationFailed: Authentication failed for user [email protected]

I would really appreciate any help as this is my very first time deploying to an Ubuntu server and I would really like to learn what it is I'm doing wrong. Thank you in advance.

like image 671
Ctpelnar1988 Avatar asked Dec 28 '16 20:12

Ctpelnar1988


3 Answers

Did you add your key to the Agent?

What do you see when you run:

$ ssh-add -l

If you get 'The agent has no identities.', then add your key with:

$ ssh-add id_rsa_key_name
like image 175
bryanus Avatar answered Nov 01 '22 01:11

bryanus


First of all you need to ssh to your server and run

eval `ssh-agent`

and then

ssh-add ~/.ssh/id_rsa

and now change

set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
# 

to

set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa) }
#

I just removed pub from id_rsa.pub.

And then run

cap production deploy:initial

It should work now. Same changes fixed the issues for my app https://www.wiki11.com.

like image 9
Neeraj Kumar Avatar answered Oct 31 '22 23:10

Neeraj Kumar


You have : set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }

Change it to: set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa) }

Keys should have private key location only. Also, enable ssh-agent on local machine using ssh-add. Add ForwardAgent yes in ~/.ssh/config for your Host.

like image 4
Vivek Avatar answered Oct 31 '22 23:10

Vivek