sudo in bash, permission denied [duplicate]

时间:2021-03-17 02:42:41

This question already has an answer here:

这个问题在这里已有答案:

I want to block usb mass storage in some of the systems in the LAN. I have written a bash script which will modify the file. I am running the script as default admin in ubuntu. But the script is not able to modify the file. I am getting the following error "bash: /etc/modprobe.d/blacklist.conf: Permission denied"

我想在局域网的某些系统中阻止USB大容量存储。我写了一个bash脚本来修改文件。我在ubuntu中运行脚本作为默认管理员。但该脚本无法修改该文件。我收到以下错误“bash:/etc/modprobe.d/blacklist.conf:权限被拒绝”

Below is my bash script

下面是我的bash脚本

#/bin/bash
password='mypassword'                  #admin password of remote system
val='blacklist usb-storage'            #text which i want to add in the file
for sysName in $(cat systemDetails)    #systemDetails is file which stores
do
ssh $sysName 'echo '$password' | sudo -S echo '$val ' >> /etc/modprobe.d/blacklist.conf'
echo
done
#script ends

NOTE: I have configured my system such that no ssh password is required.

注意:我已配置我的系统,因此不需要ssh密码。

Any pointers in this regard will be really helpful.

这方面的任何指示都会非常有帮助。

1 个解决方案

#1


-2  

Try this:

ssh $sysName "echo $password | sudo -S sh -c 'echo $val >> /etc/modprobe.d/blacklist.conf'"

#1


-2  

Try this:

ssh $sysName "echo $password | sudo -S sh -c 'echo $val >> /etc/modprobe.d/blacklist.conf'"