简体   繁体   中英

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. 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. I have tried the following:
echo "abcd" | su
But it still ends up asking for the password again.

You should try NOPASSWD option. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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