0

我想用 su 在一个命令行中更改用户

echo password | su user

但这不起作用。还有其他可能吗?最良好的祝愿

4

3 回答 3

3

首先:问问自己是否真的有必要让脚本知道密码。sudoSE-Linux 通常会为您提供很多选项来避免输入密码。

这就是说,su打开它的控制终端来读取密码,而不是标准输入。您可以使用sudo选项-S从标准输入读取密码。

于 2012-04-26T11:39:32.623 回答
1

来自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. 
于 2012-04-26T11:42:46.453 回答
0

做以下..

passwd root 它会要求您输入新密码输入它然后您以管理员身份登录并执行您想要的操作

于 2012-04-26T11:36:41.540 回答