title: Execute commands as different user via sudo over SSH in a justfile
body: <p>I have this justfile:</p>
  <pre><code>remote:
      #!/usr/bin/env bash
      read -p 'Password:' -s password
      ssh -tt somewhere 'bash -l -s' &lt;&lt; 'ENDSSH'
      whoami
      echo &quot;$password&quot; | sudo su someone 'bash -l -s' &lt;&lt; 'ENDSUDO'
      whoami
      ENDSUDO
      ENDSSH
  </code></pre>
  <p>It should:</p>
  <ul>
  <li>Ask me for a password</li>
  <li>SSH into somewhere</li>
  <li>sudo to change the user</li>
  <li>execute some scripts</li>
  </ul>
  <p>What it does:</p>
  <p>It asks for a password a second time.
  It stucks on input (no error message).</p>
  <p>How to solve this problem?</p>
  <h2>Update</h2>
  <p>As suggested by @xhienne, this does almost work, but it says, I use the wrong password:</p>
  <pre><code>remote:
      #!/usr/bin/env bash
      read -p 'Password:' -s password
      ssh -tt somewhere 'bash -l -s' &lt;&lt; 'ENDSSH'
      sudo -S -i -u someone &lt;&lt; ENDSUDO
      $password
      whoami
      ENDSUDO
      exit
      ENDSSH
  </code></pre>
  <p>But this does work:</p>
  <pre><code>remote:
      #!/usr/bin/env bash
      read -p 'Password:' -s password
      ssh -tt somewhere 'bash -l -s' &lt;&lt; 'ENDSSH'
      sudo -S -i -u someone &lt;&lt; ENDSUDO
      clear-text-password
      whoami
      ENDSUDO
      exit
      ENDSSH
  </code></pre>
  <h2>Update 2</h2>
  <p>The answer of @xhienne does work.</p>