我有一个rails应用程序,用户可以提交表单并通过ssh连接到远程服务器来调用脚本。最终,我计划使用delayed_job或类似的东西,但即使是简单的测试,我也无法使它在生产中工作。
奇怪的是,Net::SSH在生产中从控制台运行得很好,但是当我在生产中提交表单时,它在AuthenticationFailed中失败了。在开发过程中,控制台和webapp都工作得很好。
错误:
网::SSH::AuthenticationFailed (my_ssh_username):
app/models/Branch.rb:69:在ssh\_to\_machine' app/controllers/branches\_controller.rb:55:in更新中
控制器的更新操作:
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示例复制/粘贴:
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我已经尝试过使用和不使用:详细、键、:auth_methods;每次都要小心地重新启动apache,但是在生产过程中,它总是从控制台运行(在调用'rails c‘之前导出RAILS_ENV=production ),而从不在webapp中工作。
当我从webapp调用它时,我也会欢迎任何关于如何增强日志记录的建议- :verbose在控制台为我工作,但没有为我的production.log添加任何东西。
发布于 2012-05-17 03:12:40
当您从控制台运行它时,您使用的是您自己的帐户,对吗?
这有点奇怪,但我的猜测是,您的生产web应用程序是在一个帐户下运行的,它没有读取"/home/www-data/.ssh/ my _ssh_username_id_rsa“的访问权限。
根据您的描述,它几乎必须是某种类型的权限问题。
https://stackoverflow.com/questions/7533170
复制相似问题