Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash sudo:需要密码_Bash_Icinga2 - Fatal编程技术网

Bash sudo:需要密码

Bash sudo:需要密码,bash,icinga2,Bash,Icinga2,我正在尝试将ssh密钥复制到脚本从列表中读取的所有主机,并将ssh复制到这些主机,然后运行一些yum install命令: while read f; do ssh-copy-id -f myusername@"$f" ssh myusername@"$f" ' yum install -y epel-release wget --no-check-certificate https://packages.icinga.org/epel/7/relea

我正在尝试将ssh密钥复制到脚本从列表中读取的所有主机,并将ssh复制到这些主机,然后运行一些
yum install
命令:

while read f; do
   ssh-copy-id -f myusername@"$f"
   ssh myusername@"$f" '
        yum install -y epel-release
        wget --no-check-certificate https://packages.icinga.org/epel/7/release/noarch/icinga-rpm-release-7-1.el7.centos.noarch.rpm
        sudo -n yum install -y icinga-rpm-release-7-1.el7.centos.noarch.rpm
        yum install -y icinga2  nagios-plugins-all
        rm -rf /etc/icinga2/conf.d/*
        rm -f /etc/icinga2/zones.conf
我得到一个错误:

sudo: a password is required 
bash: line 7: /etc/icinga2/zones.conf: Permission denied
如果我添加-I(
sudo-I
),那么我将得到:

sudo: no tty present and no askpass program specified
bash: line 7: /etc/icinga2/zones.conf: Permission denied
你能帮忙吗


谢谢

您没有使用
sudo
运行任何shell,因此不需要使用
-i
选项。您需要做的是删除
-n
参数,以便
sudo
可以提示您输入密码,告诉
ssh
sudo
提供一个用于提示的终端,并确保对所有需要密码的命令都使用
sudo

差不多

while read f; do
   ssh-copy-id -f myusername@"$f"
   ssh -t myusername@"$f" '
        sudo yum install -y epel-release
        wget --no-check-certificate https://packages.icinga.org/epel/7/release/noarch/icinga-rpm-release-7-1.el7.centos.noarch.rpm
        sudo yum install -y icinga-rpm-release-7-1.el7.centos.noarch.rpm
        sudo yum install -y icinga2  nagios-plugins-all
        sudo rm -rf /etc/icinga2/conf.d/*
        sudo rm -f /etc/icinga2/zones.conf
        '

除了这个答案,如果你想完全自动化这个,你可以做
echo“$pass”| sudo-S
。如果您真的想自动执行此操作,请在远程主机上获取
expect
。或配置
sudo
,以便在不使用密码的情况下运行这些命令。@chepner,谢谢,但我使用您的解决方案收到此错误:sudo:no tty present and no askpass program specified matiasberrios-谢谢,您的解决方案有效,但那样的话,我必须将密码以明文形式发送到每台服务器:-(尝试使用
-ntt
而不是
-t
。无论如何,您需要使用
-n
/dev/null
重定向标准输入,以防止
ssh
在再次调用
read
之前读取循环的其余输入,并且您需要
-tt
而不是
-t
来强制使用伪项。)由于
ssh
没有虚拟终端,因此需要分配一个虚拟终端(它可能仍然会失败;我不完全理解在此设置中伪终端与
sudo
的交互。)这不是一个编程问题,也是一个常见的常见问题解答。请在或上搜索错误消息。如果您仍然需要帮助,则需要更详细地了解您预期会发生什么以及在
sudoers
中配置了什么。我记得上周在回答您之前的一个问题时解释了此问题。