简体   繁体   中英

Running linux commands inside bash script throws permission denied error

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM