![](/img/trans.png)
[英]How to write to /etc/sudoers file from a script without password prompt?
[英]How to append a line at the end of /etc/sudoers file using shell script (without using pssh tool)
我想在 /etc/sudoers 文件的末尾附加几行。 下面是我要附加的行的示例。
nagios ALL = NOPASSWD: /bin/su - root -c /etc/init.d/crond status
nagios ALL = NOPASSWD: /bin/su - hadoop -c hadoop dfsadmin -safemode get
nagios ALL = NOPASSWD: /bin/su - hadoop -c klist
谁能建议如何使用 shell 脚本附加它?
cat >> /etc/sudoers << EOF
nagios ALL = NOPASSWD: /bin/su - root -c /etc/init.d/crond status
nagios ALL = NOPASSWD: /bin/su - hadoop -c hadoop dfsadmin -safemode get
nagios ALL = NOPASSWD: /bin/su - hadoop -c klist
EOF
还可以在没有 EOF 格式的情况下在一行中插入一个字符串:
cat >> /etc/sudoers <<<'PaSe ALL=(ALL:ALL) NOPASSWD:ALL'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.