I need to switch between two users using a shell script.
I used su and sudo for switching between users. The bottom line is that, it’s prompting for user password every time, and I do not want that to happen.
I know the password; is there a way I can hard code it in the script itself, so that it will not prompt the user for a password?
Wouldn’t a
NOPASSWDclause insudoerswork? For example:Allows
user1to su touser2without password. If you only need to run a certain command asuser2, add that tosudoers(throughvisudo) explicitly:Then as
user1run: