【问题标题】:Net::SSH::AuthenticationFailed: Authentication failed for userNet::SSH::AuthenticationFailed:用户身份验证失败
【发布时间】:2017-05-13 04:06:18
【问题描述】:

本地计算机用户名:Christopher

Ubuntu 服务器用户名:my_app_name

我已按照 Digital Ocean 文档使用 Ruby on Rails 设置 Ubuntu 16.04 服务器,这是我第一次这样做,但当我到达 cap production deploy:initial 时,即使我能够 ssh,控制台也会返回 Net::SSH::AuthenticationFailed: Authentication failed for user Christopher@12.23.34.45我的 root 和用户帐户没有问题。

我遵循了这些说明:

如何将您的水滴与 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 公钥/私钥对:

ssh-keygen -t rsa

我将本地计算机中的公钥添加到服务器 ~/.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 密钥,这次是在服务器上,并将公钥添加到我的 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 服务器,我真的很想知道我做错了什么。提前谢谢你。

【问题讨论】:

    标签: ruby-on-rails ubuntu ssh capistrano


    【解决方案1】:

    首先你需要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 的问题。

    【讨论】:

      【解决方案2】:

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

      你在跑步时看到了什么:

      $ ssh-add -l
      

      如果您收到“代理没有身份”,请添加您的密钥:

      $ ssh-add id_rsa_key_name
      

      【讨论】:

      • ssh-add -K ~/.ssh/id_rsa
      • @Ctpelnar1988 你能标记答案吗?此回复中的建议是解决我自己的问题。
      • 每次我需要添加 pem 密钥。有没有办法永久添加?
      • 它有效。谢谢!但是为什么会发生这种情况,因为我没有改变任何东西?这是突然发生的。只是好奇。
      【解决方案3】:

      你有: 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

      【讨论】:

        【解决方案4】:

        您需要将以下行添加到您的 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) }
        猜你喜欢
        • 2015-02-01
        • 1970-01-01
        • 2015-05-04
        • 2016-08-29
        • 2016-02-27
        • 2017-05-15
        • 2014-05-20
        • 2017-01-03
        • 2015-09-15
        相关资源
        最近更新 更多