1

I'm trying to log into a remote machine using SSH in my Ruby code and then trying to cd into another directory once I SSHed in. Here is my Ruby code to do it

require 'net/ssh'
require 'rubygems'
require 'needle'

Net::SSH.start('host', 'shui', :password => "password") do |ssh|
   output = ssh.exec!("hostname")
   shell = ssh.shell.open
   shell.pwd
   shell.cd "/svn"
   puts shell.pwd
end

when I run my script, it gives me this error:

testssh.rb:8:in `block in <main>': undefined method `shell' ... (NoMethodError)

I'm pretty sure I've installed the gems that are needed to do this. Any suggestions on how to fix this? Thanks!

2 Answers 2

2

There is no shell method in Net:SSH v2, the yielded object is a Net::SSH::Connection::Session.

This net-ssh extension gives you the feature you are looking for: https://github.com/mitchellh/net-ssh-shell

Sign up to request clarification or add additional context in comments.

Comments

1

Can you check your version?

gem list --local | grep ssh

i have 2.5.2

I found multiple references online, but you should use:

http://net-ssh.rubyforge.org/ssh/v2/api/classes/Net/SSH.html

here is the reference to v1

http://net-ssh.github.com/ssh/v1/chapter-5.html

the later, uses the shell method. But i don't think you have that gem installed.

So have a look at the 1st one (v2). Thats working fine for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.