Net::SSH::AuthenticationFailed: 用户身份验证失败

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

本地计算机用户名:Christopher

Ubuntu 服务器用户名:my_app_name

我已经按照 Digital Ocean 文档设置了一个 Ubuntu 16.04 服务器,在 Rails 上使用 Ruby,这是我第一次这样做,虽然当我到达 cap production deploy:initial 控制台 returns Net::SSH::AuthenticationFailed: Authentication failed for user Christopher@12.23.34.45 即使我能够毫无问题地通过 ssh 进入我的 root 和用户帐户。

我遵循了这些说明:

如何将您的 droplet 与 Digital Ocean 连接 https://www.digitalocean.com/community/tutorials/how-to-connect-to-your-droplet-with-ssh

初始服务器设置 Ubuntu 16.04
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04

我在我的本地计算机上生成了一个 ssh public/private 密钥对:

ssh-keygen -t rsa

我将 public 密钥从我的本地计算机添加到服务器 ~/.ssh/authorized_keys 文件中。然后我可以通过 ssh 进入我的 root 和用户帐户。

然后我按照这些说明操作:

使用 Capistrano、Nginx 和 Puma 在 Ubuntu 14.04 上部署 Rails 应用程序 https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma

我生成了另一个 ssh 密钥,这次是在服务器上并将 public 密钥添加到我的 github 的部署密钥列表中。然后我能够通过 ssh 成功克隆我的 repo。

我运行以下命令:

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

cap production deploy:initial

然后回来:

Net::SSH::AuthenticationFailed: Authentication failed for user Christopher@12.23.34.45

我非常感谢任何帮助,因为这是我第一次部署到 Ubuntu 服务器,我真的很想知道我做错了什么。提前谢谢你。

您需要将以下行添加到您的 config/deploy.rb

ssh_options[:forward_agent] = true

参考this post.

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

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

密钥应该只有私钥位置。此外,使用 ssh-add 在本地计算机上启用 ssh-agent。在 ~/.ssh/config 中为您的主机添加 ForwardAgent yes

您是否将密钥添加到代理?

当你运行时你看到了什么:

$ ssh-add -l

如果您得到 'The agent has no identities.',则添加您的密钥:

$ ssh-add id_rsa_key_name

首先你需要ssh到你的服务器然后运行

eval `ssh-agent`

然后

ssh-add ~/.ssh/id_rsa

现在改变

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

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

我刚刚从 id_rsa.pub 中删除了 pub

然后运行

cap production deploy:initial

现在应该可以了。相同的更改修复了我的应用 https://www.wiki11.com.

的问题