Net::SSH with non unix/linux host?
I assume it works fine when you login in the shell manually.
To understand what is the difference when you connect through net/ssh collect output of env
command in both cases and compare.
That most probably you'll see a difference that will lead you to a solution or at least will give you dirty trick.
UPDATE. (Not working)
Net::SSH.start('10.204.121.192', 'password', :password => "password") do |ssh|
ssh.open_channel do |channel|
channel.on_data do |ch, data|
puts "got data: #{data.inspect}"
end
channel.send_data("INH-MSG-ALL;\n")
end
end
UPDATE2. (Working)
Net::SSH.start('10.204.121.192', 'password', :password => "password") do |ssh|
ssh.open_channel do |channel|
channel.send_channel_request "shell"
channel.on_data do |ch, data|
puts "got data: #{data.inspect}"
end
channel.send_data("INH-MSG-ALL;\n")
end
end
ruby net-ssh calling bash script with interactive prompts
managed to fix this by using the channel function, here's the method I use now
def connect(host,command)
require 'rubygems'
require 'net/ssh'
user = LocalConfig::SSH_DETAILS[:user]
pass = LocalConfig::SSH_DETAILS[:pass
o = ""
Net::SSH.start(host, user, :password => pass, :paranoid => false, :auth_methods => ['password'], :timeout => 30 )do |ssh |
channel = ssh.open_channel do |ch|
ch.exec(command) do |ch2, success|
ch2.send_data "myUserName\n"
ch2.send_data "mPassWord\n"
ch.on_data do |ch2, data|
o += data
end
end
end
channel.wait
return o.to_s
end
end
ruby net-ssh login shell
Net-SSH is too low level to simply provide this up front (the way it is now, anyways). You can check out Net-SSH-Shell which builds upon Net-SSH to add login shell functionality: https://github.com/mitchellh/net-ssh-shell
The implementation is solid and works, however I found its not too useful since you can't specifically extract things like stderr or exit status because the commands run in a sub-shell, so you can only get stdout. The net-ssh-shell library uses some hacks to get the exit status.
I've needed a "login shell" for my own Ruby projects and to do this I've generally executed things directly into the shell using the following code:
def execute_in_shell!(commands, shell="bash")
channel = session.open_channel do |ch|
ch.exec("#{shell} -l") do |ch2, success|
# Set the terminal type
ch2.send_data "export TERM=vt100\n"
# Output each command as if they were entered on the command line
[commands].flatten.each do |command|
ch2.send_data "#{command}\n"
end
# Remember to exit or we'll hang!
ch2.send_data "exit\n"
# Configure to listen to ch2 data so you can grab stdout
end
end
# Wait for everything to complete
channel.wait
end
With this solution you still don't get exit status or stderr of commands run into the login shell, but at least the commands are executed in that context.
I hope this helps.
Unable to run perl script for ssh login to Windows server (using Net::SSH::Perl) from crontab
It looks like host key verification is failing preventing the authentication. There may be host keys stored in ~/.ssh/known_hosts in the user's(root) home directory try deleting the remote host key from "known_hosts" and then re-try.
Related Topics
Ruby Devise, Sessionscontroller.Create, JSON - Getting Nameerror: Undefined 'Build_Resource'
Ruby Implementation Win32API Get Mouse Scroll/Wheel Input
Nomethoderror on Section 5.7 of Rails Guide
How to Access Ruby Method Inside Module and Inside a Class from Another .Rb File
I Want to Match All Punctuation in My Regexp Except Apostrophes. How to Do That in Ruby
Ruby - Append Data to Existing JSON
Continuous Integration for Ruby on Rails
Fetch VS. [] When Working with Hashes
Ruby on Rails: Adding Columns to Existing Database
Check If String Is Repetition of an Unknown Substring
Issue with Precision of Ruby Math Operations
Rails: How to Use Scope to Find an Element in Array of Arrays
Ruby Selenium Web Drive: How to Find Specific Element by Xpath Div Id and CSS Class