title: Running linux commands inside bash script throws permission denied error
body: <p>We have linux script in our environment which does ssh to remote machine with a common user and copies a script from base machine to remote machine through <code>scp</code>. </p>
  
  <p>Script Test_RunFromBaseVM.sh</p>
  
  <pre><code>#!/bin/bash
  
  machines = $1
  for machine in $machines
  do
      ssh -tt -o StrictHostKeyChecking=no ${machine} "mkdir -p -m 700 ~/test" 
      scp -r bin conf.d ${machine}:~/test
      ssh -tt ${machine} "cd ~/test; sudo bash bin/RunFromRemotevm.sh"
  done
  </code></pre>
  
  <p>Script RunFromRemotevm.sh</p>
  
  <pre><code>#!/bin/bash
  echo "$(date +"%Y/%m/%d %H:%M:%S")"
  </code></pre>
  
  <p>Before running Test_RunFromBaseVM.sh script base vm we run below two commands.</p>
  
  <p><code>eval $(ssh-agent)</code><br>
  <code>ssh-add</code></p>
  
  <p>Executing <code>./Test_RunFromBaseVM.sh "&lt;list_of_machine_hosts&gt;"</code> getting permission denied error.</p>
  
  <p><code>[remote-vm-1] bin/RunFromRemotevm.sh:line 2: /bin/date: Permission denied</code></p>
  
  <p>any clue or insights on this error will be of great help.
  Thanks.</p>