title: Linux shell script - How to switch user and run a script?
body: <p>I'm currently writing a .sh script to deploy different applications on 4 different machines. Right now I'm having trouble with running a script as another user. I need to log in with myUser with my credentials and then sudo su to user2 to run a specific script.</p>
  
  <p>Normally, I would manually do the following:</p>
  
  <pre><code>ssh myUser@remotehost
  [Type in password]
  sudo su - user2
  cd /path/only/accessible/to/user2
  ./someScript.sh
  </code></pre>
  
  <p>when I tried</p>
  
  <p><code>ssh -t myUser@$remotehost "sudo su - user2 &amp;&amp; /path/only/accessible/to/user2 &amp;&amp; ./someScript.sh"</code></p>
  
  <p>I was asked my password, then stayed logged as user2, without any feedback from the script, which would normally give me some informations.</p>
  
  <p>What am I doing wrong?</p>