Non interactive su in bash script

Hi,

I have a python gui which allow users entering the root password, then a bash script is called to run "su" with the root password on the background. I could find a way to run "su" with a password. How to run "su" in a bash script without password prompt?

Thank you.

The "problem" is not bash, it is su. You are asking it to let you create a security hole. It has code to avoid doing that.

Since you seem to know the root passwd, try using sudo. This means you have to set up the /etc/sudoers file. Then certain users are allowed whatever privilege you give them when they execute sudo.

If you are bound and determined to do something insecure, try using expect. This lets you put passwords in a shell script to su.

Thanks for the response, I know things would be easy if I could personally access the machines and doing all sorts of things by typing keys. I am talking about the program and I won't use expect.

I am surprised that you have a root password but you cannot do anything to login to the root to do root permission things in Linux program.

I have seen many GUI programs to let you enter the root password then to access root files. Seems there are some ways to log into the root with root password in Linux program, right?

Thank you.

Try using the authorized_keys concept and once you make an ssh using the root password, next time onwards, it'll not ask the root password.

Thanks for the response. But there is no ssh login to run the script, the scripts are installed and run when users click from the menu.