LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-26-2005, 08:55 PM   #1
c0d3
LQ Newbie
 
Registered: Nov 2004
Location: Philippines
Distribution: Red Hat Advanced Server
Posts: 16

Rep: Reputation: 0
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.
 
Old 07-26-2005, 10:33 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Well, the ideal mechanism would be to use the sudo package for this.
 
Old 07-27-2005, 12:57 AM   #3
c0d3
LQ Newbie
 
Registered: Nov 2004
Location: Philippines
Distribution: Red Hat Advanced Server
Posts: 16

Original Poster
Rep: Reputation: 0
Ok Matir,I'll try your suggestion. Thanks.
 
Old 07-27-2005, 01:27 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,492

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
"su - user" is not prompting for a password if you run the script as root.
 
Old 07-27-2005, 08:46 AM   #5
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
I believe his intent is to go user1 -> user2, neither user being root. But I could be wrong.
 
Old 07-27-2005, 11:22 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,492

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
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.
 
Old 07-27-2005, 11:34 AM   #7
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
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)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
add user bash script noir911 Programming 4 08-13-2005 08:24 AM
Change Text-File through bash script arkus Programming 2 12-17-2004 08:48 PM
change console title in bash script? TLV Linux - Software 18 10-08-2004 11:25 AM
Bash script to change a filename associated with an inode index number. Ziv Programming 22 06-19-2004 08:41 AM
User input using a BASH script... causticmtl Programming 5 07-13-2003 09:59 PM


All times are GMT -5. The time now is 04:26 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration