spawn a process with a different user


 
Thread Tools Search this Thread
Top Forums Programming spawn a process with a different user
# 1  
Old 11-09-2010
spawn a process with a different user

Hello Everyone:

I have the following code

Code:
int main()
{
   system("/usr/OtherUser/bin/runX");
  return 0;
}

runX must be executed with privileges from another user, how could I do that? I know the password for such user.

Thanks in advance
# 2  
Old 11-09-2010
There is su, but I am not sure if su reads sdin for password (ssh2 reads /dev/tty, so you need a tty generating wrapper like expect):
Code:
 
system( "su - user -c /usr/OtherUser/bin/runX");

You can use rsh/ssh/ssh2 trusted access:
Code:
system( "ssh2 -n user@localhost /usr/OtherUser/bin/runX");

# 3  
Old 11-09-2010
Hello DGPickett, Thanks for quick response

su does read from stdin, unfortunately seems stdin is flushed before su prompts for the password, so I must wait for two seconds before entering the password but I don't know how.

Thanks again
# 4  
Old 11-09-2010
Quote:
Originally Posted by DGPickett
There is su, but I am not sure if su reads stdin for password
For obvious security reasons, it doesn't, just like any other sane command that takes a password.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 11-09-2010
Let's assume you not trying to hack a privileged account...
can you make /usr/OtherUser/bin/runX setuid.

And give yourself group execute?
This User Gave Thanks to purdym For This Post:
# 6  
Old 11-09-2010
Two ideas that comes to my mind:
  • why should the runX be run with the priviledges of OtherUser. If the reason is because of files permissions, a better solution could involve putting User and OtherUser in the same group
  • If you still need to runX as OtherUser, I would recommend to use sudo (instead of su). You can configure sudo to run the program as OtherUser from User without password query
HTH,
Loïc
This User Gave Thanks to Loic Domaigne For This Post:
# 7  
Old 11-09-2010
The ssh seems like overkill but is more secure. Two seconds, oh whoop!
Code:
 
system( "(sleep 3;echo the_password)|su - -c /usr/OtherUser/bin/runX" );

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sleep 600 or fork/spawn a process or daemon?

Hi, I have a script that run every 10 minutes, from a specific timeframe of the day, for example 0500 - 1900. The script is some sort of checker script for an application log file and check for errors and email us if there is error/s reported in the log. At the moment, I schedule it... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. Solaris

Process for user

Hi folks, How can I list all the processes that running by a specific user, I don't know if ps -u USERID can help me in that, is there any other way to get a full information about the current services and process information which related to the users. Thanks (4 Replies)
Discussion started by: leo_ultra_leo
4 Replies

3. Shell Programming and Scripting

Spawn and join multiple process

I am doing some file manipulation and then a bcp once all the files are processed. I need to do the following for all files in dirctory begin -Step 1 use another shell/perl to format the file done in the end load into db using bcp I want to do step 1 and step in a seperate... (2 Replies)
Discussion started by: tasmac
2 Replies

4. Shell Programming and Scripting

Hide the output of spawn ssh user@server

Hi All, I have written one script, which is connecting 3 diffrent servers and executing script placed on those. It is smthing like: spawn ssh user@server1 expect "*? assword:" send "pw \r" expect "$" send " sh ./filename1 \r" expect "$" expect eof spawn ssh user@server2 expect "*?... (7 Replies)
Discussion started by: KDMishra
7 Replies

5. Shell Programming and Scripting

Using expect command, spawn will not start sftp process

Hi all, I have a script that runs sftp with expect so I can login and send a file in a cronjob. I've installed this on a couple other servers and it has been fine. However, this time on this machine, it seems to be giving me an issue. It won't move past the spawn sftp command and return a... (3 Replies)
Discussion started by: ltyrrell
3 Replies

6. Shell Programming and Scripting

List of process of user

Hi, I need an output of process running on server, i am executing ps -ef | grep test output is asak 22362 1 0 Nov07 ? 00:00:03 /usr/software/bin/perl-5.8.8 /u/assk/bin/test -v none JOBID=2012117 asak 23748 22362 0 Nov07 ? 00:00:00 /usr/software/bin/perl-5.8.8... (3 Replies)
Discussion started by: asak
3 Replies

7. Shell Programming and Scripting

Move Process ID from one user to another

HI, I'm search to transfer a process ID form the User A to the User B with out super user privilege. Would it be possible. Please leave your (1 Reply)
Discussion started by: Prabhu.Are
1 Replies

8. Shell Programming and Scripting

User Input Automation without Spawn

Hello All! I am attempting to create a shell script that will execute another shell script (mandatory by 3rd party software I'm attempting to automate). What I want to do is simply this, once the shell script is run, it will execute the other shell script (I have that done fine and working),... (8 Replies)
Discussion started by: foghsho
8 Replies

9. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

10. UNIX for Dummies Questions & Answers

What user is a process running as?

How do you determine what user a process is running as? I want to know what user proftpd is running as, and what user a script that I have is running as. Thanks. (1 Reply)
Discussion started by: america2
1 Replies
Login or Register to Ask a Question