LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to change user in bash script (https://www.linuxquestions.org/questions/programming-9/how-to-change-user-in-bash-script-347127/)

c0d3 07-26-2005 08:55 PM

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.

Matir 07-26-2005 10:33 PM

Well, the ideal mechanism would be to use the sudo package for this.

c0d3 07-27-2005 12:57 AM

Ok Matir,I'll try your suggestion. Thanks.

jlliagre 07-27-2005 01:27 AM

"su - user" is not prompting for a password if you run the script as root.

Matir 07-27-2005 08:46 AM

I believe his intent is to go user1 -> user2, neither user being root. But I could be wrong.

jlliagre 07-27-2005 11:22 AM

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.

Matir 07-27-2005 11:34 AM

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.