title: Run script as another user on Linux
body: <p>I am trying to create a Linux terminal menu by way of a simple script. Within the script it will have some commands that will submit a job (a shell script for example) as another user without password prompt. </p>
  
  <p>I was able to find the following post and this worked. <strong><a href="https://stackoverflow.com/questions/6905697/how-to-run-script-as-another-user-without-password">how to run script as another user without password</a></strong>
  However, there was one side affect. It appears the user can run other scripts in that users folder which I don't want.</p>
  
  <p>Any suggestions/help welcome.</p>
  
  <p>For the sake of this. Here is what I have:</p>
  
  <ol>
  <li><p>Username <code>temp1</code>, which is the user that will be running the menu. 
  uid=1001(temp1), gid=1001(temp1), groups=1001(temp1)</p></li>
  <li><p>Username <code>wayne</code>, which is the user that the script must be submitted as to run the job
  uid=1000(wayne), gid=1000(wayne),groups=1000(wayne),4(adm),24(cdrom),27(sudo),30(dip)...</p></li>
  <li><p>Script <code>script1.sh</code>, <code>script2.sh</code> owned by <code>wayne</code>. </p>
  
  <pre><code>-rwxr-xr-x script1.sh
  -rwxr-xr-x script2.sh
  </code></pre></li>
  <li><p>If I try to go to <code>/home/wayne</code> as <code>temp1</code> user I get permission denied (expected)</p></li>
  <li><p>I set the scripts to chmod 700 for <code>wayne</code>. So technically no one can run them other than <code>wayne</code>.</p></li>
  <li><p>I have edited sudo file and have the following entry:</p>
  
  <pre><code>temp1 ALL(wayne) NOPASSWD: /home/wayne/script1.sh
  </code></pre></li>
  <li><p>When I run command <code>su -c "/home/wayne/script1.sh" -s /bin/sh wayne</code> the script runs (as expected)</p></li>
  <li><p>When I run command <code>su -c "/home/wayne/script2.sh" -s /bin/sh wayne</code> the script runs (not expected).</p></li>
  </ol>
  
  <p>Any ideas?</p>