title: How to handle password expire in SSH.net
body: <p>I uses SSH.net to connect to my Linux. Password expires every 30 days.
  One of requirements is to reset the password automatically.</p>
  
  <p>But it failed.</p>
  
  <p>In response.error, it is always 
          Error   "WARNING: Your password has expired.\nPassword change required but no TTY available.\n" </p>
  
  <p>Code Sample as below</p>
  
  <p>class Program
      {
          String host = "host";
          int port = 22;
          String username = "user";
          String password = "passwd";
          String newpassword = "newpasswd";</p>
  
  <pre><code>    PasswordConnectionInfo connectionInfo;
  
      void HandlePasswordExpired(Object sender, AuthenticationPasswordChangeEventArgs e)
      {
          e.NewPassword = UTF8Encoding.UTF8.GetBytes(newpassword);
      }
  
  
      void Init()
      {
          connectionInfo = new PasswordConnectionInfo(host, username, password);
  
          connectionInfo.PasswordExpired += HandlePasswordExpired;
  
      }
  
      void TestConnection()
      {
          try
          {
  
              using (var client = new SshClient(connectionInfo))
              {
                  client.Connect();
                  var resp = client.RunCommand("ls -l /");
                  Console.WriteLine("Resp -&gt; {0}", resp.Result);
                  client.Disconnect();
              }
          }
          catch (Exception e)
          {
              Console.WriteLine(e);
          }
      }
  
      static void Main(string[] args)
      {
          Program prog = new Program();
          prog.Init();
          prog.TestConnection();
      }
  }
  </code></pre>