Net :: SSH可通过生产Rails控制台运行,AuthenticationFailed from生产Webapp [英] Net::SSH works from production rails console, AuthenticationFailed from production webapp

查看:107
本文介绍了Net :: SSH可通过生产Rails控制台运行,AuthenticationFailed from生产Webapp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails应用程序,用户可以在其中提交表单,表单会关闭并通过ssh连接到远程服务器以调用脚本.最终,我计划使用delay_job或类似的方法,但即使通过简单的测试也无法使其在生产中正常工作.

I have a rails app where a user can submit a form and it goes off and connects to a remote server via ssh to call a script. Eventually I plan to use delayed_job or something like that but I can't get it to work in production with even a simple test.

奇怪的是,Net :: SSH在生产中的控制台上工作正常,但是当我在生产中提交表单时,它以AuthenticationFailed失败.控制台和webapp都可以在开发中正常工作.

The odd thing is, Net::SSH works just fine from the console in production, but it fails with AuthenticationFailed when I submit the form in production. Both the console and the webapp work fine in development.

错误:

Net :: SSH :: AuthenticationFailed(my_ssh_username):

Net::SSH::AuthenticationFailed (my_ssh_username):

app/models/branch.rb:69:in ssh_to_machine'

app/models/branch.rb:69:in `ssh_to_machine'

app/controllers/branches_controller.rb:55:in更新"

app/controllers/branches_controller.rb:55:in `update'

控制器的更新操作:

  def update
    @branch = Branch.find(params[:id])
    if @branch.update_attributes(params[:branch])
      @branch.ssh_to_machine(@branch.hostname, @branch.user_name, @branch.command_to_run)
      redirect_to @branch, :notice  => "Update request now processing."
    else
      render :action => 'edit'
    end
  end

我正在调用的方法,主要是从Net :: SSH api示例复制/粘贴:

Method I'm calling, mostly copy/pasted from the Net::SSH api example:

def ssh_to_machine(host_name, user_name, command_to_run)
    require 'net/ssh'
    Net::SSH.start(host_name, user_name, { :verbose => Logger::DEBUG, :keys => %w{ /home/www-data/.ssh/my_ssh_username_id_rsa }, :auth_methods => %w{ publickey } }) do |ssh|
      # capture all stderr and stdout output from a remote process
      output = ssh.exec!("hostname")

      # run multiple processes in parallel to completion
      ssh.exec command_to_run
      ssh.loop
    end
end

我尝试过使用和不使用:verbose,:keys,:auth_methods;每次都要小心地重新启动apache,但是在生产环境中,它始终可以从控制台运行(在调用"rails c"之前已导出RAILS_ENV = production),而从webapp则无法运行.

I've tried it with and without :verbose, :keys, :auth_methods; being careful to restart apache each time, but in production it always works from the console (with RAILS_ENV=production exported before calling 'rails c') and never works from the webapp.

当我从webapp调用它时,我也欢迎有关如何获取增强日志记录的任何建议-:verbose在控制台上为我工作,但未在我的production.log中添加任何内容.

I would also welcome any recommendations on how to get enhanced logging when I do call it from the webapp - :verbose worked for me at the console but didn't add anything to my production.log.

推荐答案

从控制台运行它时,您正在使用自己的帐户,对吗?

When you run it from the console, you're using your own account, right?

这有点奇怪,但是我的猜测是您的生产Web应用程序是在没有对"/home/www-data/.ssh/my_ssh_username_id_rsa"具有读权限的帐户下运行的.

This is kinda bizarre, but my guess is that your production web app is running under an account that doesn't have read access to "/home/www-data/.ssh/my_ssh_username_id_rsa".

根据您的描述,它几乎一定是某种权限问题.

From your description it almost has to be a permissions issue of some sort.

这篇关于Net :: SSH可通过生产Rails控制台运行,AuthenticationFailed from生产Webapp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆