我试图运行,而不成为苏用户的脚本,我使用这个命令:如果我使用这个命令为“SCP“回声‘密码’|须藤-S <command>”需要密码
echo "password" | sudo -S <command>
“,”mv“,”whoami“命令,该命令工作得很好,但是当我使用”chmod“时,该命令会为我的用户请求密码。我不输入密码,并且指令工作。我的问题是系统向我要密码。我不希望系统要求输入密码。
问题ss是这样的:
[[email protected] test-dir]$ ls -lt
total 24
--wx-wx-wx 1 root root 1397 May 26 12:12 file1
--wx-wx-wx 1 root root 867 May 26 12:12 script1
--wx-wx-wx 1 root root 8293 May 26 12:12 file2
--wx-wx-wx 1 root root 2521 May 26 12:12 file3
[[email protected] test-dir]$ echo "myPassw0rd" | sudo -S chmod 111 /tmp/test-dir/*
[sudo] password for myLocalUser: I DONT WANT ASK FOR PASSWORD
[[email protected] test-dir]$ ls -lt
total 24
---x--x--x 1 root root 1397 May 26 12:12 file1
---x--x--x 1 root root 867 May 26 12:12 script1
---x--x--x 1 root root 8293 May 26 12:12 file2
---x--x--x 1 root root 2521 May 26 12:12 file3
我不能说如何重现这一点。 'sudo -S'对于需要输入的程序有点不好,因为它们的stdin被连接到密码来自的同一个管道。但'chmod'不应该期望输入,AFAIK。如果你先用'sudo -s'打开一个shell,然后执行'chmod 111 ...',那么有问题的命令会做什么?与其他有用的程序相比,是否有一些不同? – ilkkachu