Net::ssh - Drop User into shell

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