【问题标题】:How to append a line at the end of /etc/sudoers file using shell script (without using pssh tool)如何使用 shell 脚本在 /etc/sudoers 文件末尾追加一行(不使用 pssh 工具)
【发布时间】:2017-05-08 23:14:29
【问题描述】:

我想在 /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 脚本附加它?

【问题讨论】:

  • 我认为编辑/etc/sudoers 的明智方法是使用visudo。

标签: linux bash shell scripting rhel6


【解决方案1】:
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

【讨论】:

    【解决方案2】:

    也可以在一行中插入一个字符串而不使用EOF格式:

    cat &gt;&gt; /etc/sudoers &lt;&lt;&lt;'PaSe ALL=(ALL:ALL) NOPASSWD:ALL'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-26
      • 2020-11-03
      • 1970-01-01
      • 2016-05-13
      • 2013-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多