Reputation: 109
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 scp
.
Script Test_RunFromBaseVM.sh
#!/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
Script RunFromRemotevm.sh
#!/bin/bash
echo "$(date +"%Y/%m/%d %H:%M:%S")"
Before running Test_RunFromBaseVM.sh script base vm we run below two commands.
eval $(ssh-agent)
ssh-add
Executing ./Test_RunFromBaseVM.sh "<list_of_machine_hosts>"
getting permission denied error.
[remote-vm-1] bin/RunFromRemotevm.sh:line 2: /bin/date: Permission denied
any clue or insights on this error will be of great help. Thanks.
Upvotes: 0
Views: 1347
Reputation: 486
I believe the problem is the presence of the NOEXEC:
tag in the sudoers file, corresponding to the user (or group) that's executing the "cd ~/test; sudo bash bin/RunFromRemotevm.sh"
command. This causes any further execv(), execve() and fexecve() calls to be refused, in this case it's /bin/date
.
The solution is obviously remove the NOEXEC: from the main /etc/sudoers
file or some file under /etc/sudoers.d
, whereever is this defined.
Upvotes: 1