我想用 su 在一个命令行中更改用户
echo password | su user
但这不起作用。还有其他可能吗?最良好的祝愿
首先:问问自己是否真的有必要让脚本知道密码。sudo
SE-Linux 通常会为您提供很多选项来避免输入密码。
这就是说,su
打开它的控制终端来读取密码,而不是标准输入。您可以使用sudo
选项-S
从标准输入读取密码。
来自sudo
的手册:
-S
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.
做以下..
passwd root 它会要求您输入新密码输入它然后您以管理员身份登录并执行您想要的操作