# Help with net-ssh 2.0

**URL:** <https://www.ruby-forum.com/t/help-with-net-ssh-2-0/136943>\
**Category:** Ruby\
**Created:** [May 7, 2008, 4:31pm UTC](https://www.ruby-forum.com/t/help-with-net-ssh-2-0/136943 "2008-05-07T16:31:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [May 7, 2008, 4:31pm UTC](https://www.ruby-forum.com/t/help-with-net-ssh-2-0/136943/1 "2008-05-07T16:31:54Z")

</div>

Hi…,

I am trying to use net-ssh for executing unix level commands using  
net-ssh across many servers. I am looking for an example that would  
allow me to use net-ssh similar to EXPECT.

As a first step I tried the following:

* * *

#!/usr/bin/ruby

require ‘rubygems’  
require ‘net/ssh’

Net::SSH.start(‘myhostname’, ‘username’, :password =\> “password”) do  
|ssh|

#I need to sudo further into a different account  
#How do I open a channel with PTY for this as the  
#sudo fails without a proper terminal.

```
ssh.open_channel do |channel|

    channel.on_data { |ch, data| puts "stdout: #{data}" }
    channel.on_extended_data { |ch, type, data| puts "stderr:

```

#{data}" }

```
    #The following command produces output
    channel.exec "hostname"

    #The following doesnot produce any output
    channel.exec "uptime"

```

end

#Not sure what is the purpose of the next statement  
ssh.loop

end

* * *

Would anyone please show me an example script of how to open a PTY  
channel to make the sudo succeed and subsequently send commands and  
receive output from stdout and stderror.

Thanks  
Jay
