使用 echo "passwd"|sudo -S command
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.
The password must be followed by a newline character.
即-S使得sudo从标准输入读取密码而非终端
例如 在shell中执行关机命令
#!/bin/bash
echo "passwd"|sudo -S shutdown -P now
本文介绍了一种使用sudo命令时通过标准输入传递密码的方法,避免了直接在命令行中输入密码的安全风险。该方法适用于需要执行管理员权限操作但又不想暴露密码的情况。
3万+

被折叠的 条评论
为什么被折叠?



