how to change user in bash script
Hi guys,can you help me with my problem? I have a script that is supposed to run as a different user. My problem is when I include su - user in my bash script,it always asks the password of the user which should not be the case because the script would be interrupted. Im running my script on a Solaris based server. Thanks in advance.
|
Well, the ideal mechanism would be to use the sudo package for this.
|
Ok Matir,I'll try your suggestion. Thanks.
|
"su - user" is not prompting for a password if you run the script as root.
|
I believe his intent is to go user1 -> user2, neither user being root. But I could be wrong.
|
Sure, he certainly goes as you believe, as he got the prompt, I was just suggesting a different way.
As the script is looking like being non interactive, it would perhaps be easy to have it primarily run as root and switching to users on demand. On the other hand, running scripts as root induce a security risk, so sudo (or Solaris RBAC) are probably a better option. |
My biggest worry (as you say) with running scripts as root is a security risk. They are PARTICULARLY prone to symlink attacks. (i.e., putting values into /tmp/scriptname.tmp or some similar predictable file)
|
All times are GMT -5. The time now is 07:40 PM. |