title: How to SSH interactive Session
body: <p>Good day everyone</p>
  
  <p>I need to execute command on linux machine this command is interactive
  command.
  Interactive command means require input like [yes , no] or password
  twice</p>
  
  <p>my real case is.
  I create a script execute commands and get the outputs successfully.
  but some servers has Loging password expired so I need to interact with
  server to send the current password + the new password(twice)</p>
  
  <pre><code>ssh userName@10.0.0.243
  userName@10.0.0.243's password:
  You are required to change your password immediately (password aged)
  Last login: Sun Aug  7 13:15:40 2011 from 10.0.0.28
  WARNING: Your password has expired.
  You must change your password now and login again!
  Changing password for user userName.
  Changing password for userName
  (current) UNIX password:
  New UNIX password:
  Retype new UNIX password:
  </code></pre>
  
  <p>Notes::</p>
  
  <ul>
  <li>I'm using Ruby 1.9.2</li>
  <li>I've no problem in executing command in normal case</li>
  <li>please, I have to avoid workarounds like (echo "pass" | ssh -S) to make me pass any other interactive situations.</li>
  <li>I'm using 'net/ssh' libs</li>
  <li>The Script is Attached <a href="http://king-sabri.net/files/LinuxHWScanner.rb" rel="nofollow">http://king-sabri.net/files/LinuxHWScanner.rb</a></li>
  <li>I tried "net/ssh/telnet" and it doesn't help</li>
  <li>Some advises tell useing 'rake/remote_task' is the solution but I can't understand how it works in my case</li>
  </ul>
  
  <p>if you need more simplicity, here a simple code if you make it works I thing it'll solve my previous issue</p>
  
  <pre><code>  require 'net/ssh'
  
    host = "10.0.0.106"
    port = 22     # SSH port
    user = 'root'     # username
    pass = "123123"   # password
  
  Net::SSH.start( host,user,:password =&gt; pass, :port=&gt; port , :verbose =&gt; :error ) do |session|
  
   puts session.exec!("passwd root")
  end
  </code></pre>