Net::ssh - Drop User into shell

R

rilindo foster

I am trying to write a wrapper script that logs a person into a remote
system and then drop them in to the shell on that machine.

So far, it seems I am able to get as far as the prompt on the remote
system. Afterwards, though, I am unable to send any response to the
terminal.

Here is the code:

Net::SSH.start(host, username) do |ssh|
channel = ssh.open_channel do | ch|
ch.request_pty:)term => "xterm") do |ch, success|
if success
ch.send_channel_request("shell") do | ch, success |
raise "Error opening shell" unless success
end
end
end
channel.on_data do |ch, data|
STDOUT.print data
end
channel.on_extended_data do | ch, type, data|
STDERR.print "Error: #{data}"
end
end
channel.wait

I think I probably need to add something to release control of the
wrapper script to the user and it is likely a method under
net::ssh:connection:channel. I am not sure, though, which one it is or
even know how to invoke properly.

I also tried to ssh.prompt method, but apparently that is not
available when I create a channel object. Either that or I am not
doing it right?

Any suggestions? Or should I just go with wrapping the ssh binary
instead and not use Net:SSH?

- Rilindo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top