title: run a local script as root on remote server
body: <p>I try to run a local script on multiple remote servers as root. I don't have su to root on those but just can run root commands using sudo. So far I tried:</p>
  
  <pre><code>for host in $(cat hosts_list); do ssh -tt $host "echo mypassword | sudo bash -s" &lt; ./myscript.sh
  </code></pre>
  
  <p>And in myscript.sh there is something like:</p>
  
  <pre><code>echo "test test123" &gt;&gt; /etc/tests
  exit 0
  </code></pre>
  
  <p>But it looks like not working and won't change the file. What is the proper way to run this script as root and without typing password separately for each host?    </p>