Ctpelnar1988
Ctpelnar1988

Reputation: 1255

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.

Upvotes: 15

Views: 25571

Answers (5)

Besi
Besi

Reputation: 22939

I had some weird problems as long as I did not use bundler. So using capistrano like so then worked again for me:

# good
bundle exec cap production deploy

Instead of just:

# no good
cap production deploy

Upvotes: 1

Neeraj Kumar
Neeraj Kumar

Reputation: 7511

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.

Upvotes: 10

bryanus
bryanus

Reputation: 994

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

Upvotes: 58

Vivek
Vivek

Reputation: 86

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.

Upvotes: 4

Gaurav Reddy
Gaurav Reddy

Reputation: 86

You need to add the following line to your config/deploy.rb

ssh_options[:forward_agent] = true

Refer this post.

Upvotes: 0

Related Questions