简体   繁体   English

在bash脚本中运行linux命令会引发权限被拒绝错误

[英]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 . 我们的环境中有linux脚本,它可以用普通用户将ssh传输到远程计算机,并通过scp将脚本从基本计算机复制到远程计算机。

Script Test_RunFromBaseVM.sh 脚本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 脚本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. 在运行Test_RunFromBaseVM.sh脚本库vm之前,我们先运行以下两个命令。

eval $(ssh-agent)
ssh-add

Executing ./Test_RunFromBaseVM.sh "<list_of_machine_hosts>" getting permission denied error. 执行./Test_RunFromBaseVM.sh "<list_of_machine_hosts>"导致权限被拒绝错误。

[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. 我相信问题在于sudoers文件中存在NOEXEC:标记,与正在执行"cd ~/test; sudo bash bin/RunFromRemotevm.sh"命令的用户(或组)相对应。 This causes any further execv(), execve() and fexecve() calls to be refused, in this case it's /bin/date . 这将导致拒绝进一步的execv(),execve()和fexecve()调用,在这种情况下为/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. 解决方案显然是从主/etc/sudoers文件或/etc/sudoers.d下的某个文件中删除NOEXEC /etc/sudoers.d该定义在/etc/sudoers.d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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