LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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-28-2011, 02:10 PM   #1
bribon
LQ Newbie
 
Registered: Jul 2011
Posts: 8

Rep: Reputation: Disabled
Switch user in a bash script


Hi,

I need to switch from one user to another in a script in a solaris machine. No one of those users is root. I see I can use su command, but I think I can't pass the password as a parameter. I'm using bash. Is there anyway that I can switch user in a bash script?

Thanks in advance!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 07-28-2011, 02:24 PM   #2
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
You can give permissions to any users to run any script or command as root (or any other privileged user) with the sudo facility.
 
Old 07-28-2011, 02:39 PM   #3
bribon
LQ Newbie
 
Registered: Jul 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by SL00b View Post
You can give permissions to any users to run any script or command as root (or any other privileged user) with the sudo facility.
In this case I'm not using either root or any other privileged user. I need to switch between NO root users.
 
Old 07-28-2011, 03:36 PM   #4
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Well, somebody in this situation needs to have elevated privileges, otherwise, what's the point? Why switch from Dave to Bob if they both have the same privileges?

In any case, the solution is still sudo.

Here's an example... let's say Dave is responsible for the installation and maintenance of a database. The database is going to run under a service account, called dbadmin.

1) Create the dbadmin account.
2) Use the visudo command to edit the /etc/sudoers, giving Dave the rights to execute commands under the dbadmin userid, like so:
Code:
Dave     ALL = (dbadmin) ALL
3) Now Dave can execute script.sh under the dbadmin account's rights, as so:
Code:
sudo -u dbadmin script.sh
When you configure sudo, you can set it up so that Dave gets a prompt for either dbadmin's password, or his own.
 
Old 07-28-2011, 06:01 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by bribon View Post
In this case I'm not using either root or any other privileged user. I need to switch between NO root users.
What is the purpose of changing users here? Is the target user one that can log in? Can you give the two users a common group and make the appropriate files group-writable? Will the source and target users always be the same, or will they vary?
Kevin Barry
 
Old 07-28-2011, 06:11 PM   #6
bribon
LQ Newbie
 
Registered: Jul 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ta0kira View Post
What is the purpose of changing users here? Is the target user one that can log in? Can you give the two users a common group and make the appropriate files group-writable? Will the source and target users always be the same, or will they vary?
Kevin Barry
I need to back up some files from different users. Some of them are the same group, others not, so that's why I need to switch between users. The logic of the script is the same for every backup, so that's why I don't want to run multiple scripts. I'm working on multiple user machine, so I don't have access to the root user or a priviled user.

I'm using solaris and the version that I'm using doesn't support sudo command.
 
Old 07-29-2011, 08:31 AM   #7
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Quote:
Originally Posted by bribon View Post
I need to back up some files from different users. Some of them are the same group, others not, so that's why I need to switch between users. The logic of the script is the same for every backup, so that's why I don't want to run multiple scripts. I'm working on multiple user machine, so I don't have access to the root user or a priviled user.

I'm using solaris and the version that I'm using doesn't support sudo command.
If you don't have access to root, then I suggest you contact someone who does, because this is a task for root.
 
2 members found this post helpful.
Old 07-29-2011, 09:33 AM   #8
bribon
LQ Newbie
 
Registered: Jul 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by SL00b View Post
If you don't have access to root, then I suggest you contact someone who does, because this is a task for root.
That's what I thought. Thanks!
 
  


Reply



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
Run a script on switch-user event Ubuntu 9.10 bwilhite Programming 6 02-20-2010 07:44 AM
Switch statement for bash script wjs1990 Linux - Newbie 7 11-19-2009 11:37 PM
Bash, trying to program an easy debug switch in my script helptonewbie Programming 13 12-31-2008 02:02 AM
super user privileges check for a normal user in bash script freeindy Programming 2 08-01-2008 06:08 AM
How to switch user via shell script cool_anupam Linux - General 7 05-29-2008 10:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:59 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration