title: Running Sudo inside SSH with << heredoc
body: <p>I' m sure you will find the question similar to many other posts on stackoverflow or on internet. However, I could not find the solution to my problem precisely. I have list of task to be run on remote server, and passing the script is OK! however does not suit to the requirement. </p>
  
  <p>I' m running following from my server to connect to remote server; </p>
  
  <pre><code> ssh -t user@server &lt;&lt; 'HERE'
     sudo su - &lt;diff_user&gt; 
     do task as diff_user
   HERE
  
   ssh -tt user@server &lt;&lt; 'HERE'
     sudo su - &lt;diff_user&gt; 
     do task as diff_user
    HERE
  </code></pre>
  
  <p>With first option (-t), I' m still not able to do sudo, it says below;</p>
  
  <blockquote>
    <p>sudo: sorry, you must have a tty to run sudo</p>
  </blockquote>
  
  <p>With second option above (-tt), I' m getting reverse input/output to current server session, total mess.</p>
  
  <p>I tried passing the content as an script to SSH to run on remote host, however, getting similar results.  </p>
  
  <p>Is there a way other than commenting out below? </p>
  
  <blockquote>
    <p>Defaults requiretty in /etc/sudoers file </p>
  </blockquote>
  
  <p>I have not tried above though, I know RedHat approved it to be removed/ commented out in future version, whenever that is. If I go with step, I will have get above done in 100's of VM's (moreover, I dont have permission to edit the file on VM's and give it a try). </p>
  
  <blockquote>
    <p><a href="https://bugzilla.redhat.com/show_bug.cgi?id=1020147" rel="nofollow">Bug 1020147</a></p>
  </blockquote>
  
  <p>Hence, my issue remains the same, as before. It would be great if I can get some input from experts here :) </p>
  
  <p>Addition Info :  Using RedHat RHEL 6, 2.6.32-573.3.1
                   I do have access to the remote host and once I' m in, my ID does not require password to switch to diff_user.</p>