I need connect to a Cisco Switch with SSH and Ruby. The main problem is
the authentication which is different. I must enter ‘login as’, ‘User
Name’ and ‘Password’. The ‘login as’ can be any value, usually I just
press enter (empty value).
My first try was with Net::SSH but it was impossible to authenticate. I
don’t know if I did something wrong but I had always the
Net::SSH::AuthenticationFailed error then I gave up.
Now I’m trying with Plink (a command-line interface to the PuTTY back
ends). On the shell I do like this:
Now I need call and interact with Plink on Ruby. My last try was this:
IO.popen “plink -ssh [email protected]#{CISCO}”, ‘w+’ do |io|
io.each do |line|
puts line
if line.include?(‘User Name’)
io.write(USER)
elsif line.include?(‘Password’)
io.write(PASS)
end
end
end
and the error was:
‘write’: Broken pipe Errno::EPIPE
I have more than 3000 switchs. I need to work with default config =/
The option “SSH User Authentication by Password” is disabled. To enable
this option on all switchs it would take like 1 month, but could be a
solution.
I’m trying to execute shell commands and interact with them with Ruby as
I told on the first message of this topic.
I have more than 3000 switchs. I need to work with default config =/
Presumably you aren’t testing your script on all 3000 switches.
The option “SSH User Authentication by Password” is disabled. To enable
this option on all switchs it would take like 1 month, but could be a
solution.
That is why I asked if you are authenticating by key or password.
Clearly
my script is for passwords only. You can see my keys array is left
blank.
You will have to modify the class to support that. No one is asking you
to
switch to password authentication if you don’t want to.
Once you get the key thing figured out feel free to share it here. I’d
love
to add that support to my ssh class.
I’m trying to execute shell commands and interact with them with Ruby as