简体   繁体   English

使用密码切换到 root 用户的 Bash 脚本(不能使用像 expect 这样的额外库)

[英]Bash script to switch to root user with password (no additional libraries like expect can be used)

su
Enter Password: abcd
I need to be able to do the above process through a shell script.我需要能够通过 shell 脚本完成上述过程。 The issue is that it needs to be done with only the basic set of libraries that are available.问题是它只需要使用可用的基本库集来完成。 No additional libraries can be used (eg except).不能使用额外的库(例如,除外)。 Kindly do not suggest the usage of "sudo" or other things, this is the exact thing I need to do.请不要建议使用“sudo”或其他东西,这正是我需要做的事情。 I have tried the following:我尝试了以下方法:
echo "abcd" | su
But it still ends up asking for the password again.但它最终仍然再次要求输入密码。

You should try NOPASSWD option.您应该尝试 NOPASSWD 选项。 Use it for the particular command which you are going to execute for security reasons.出于安全原因,将它用于您将要执行的特定命令。 Here are two methods explained but i think second one is what exactly you need.这里解释了两种方法,但我认为第二种方法正是您所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM