To Change the user during runtime


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To Change the user during runtime
# 1  
Old 01-15-2008
To Change the user during runtime

Hi,

I have a requirement to change the user during runtime within a shell script. Is their any way via which I can change the user by prefeeding the password?

Please reply.

Thanks.
# 2  
Old 01-16-2008
Hi

I think you can use sudo like commands. I made some perl scripts, which are launched from the web (so, with apache user), but the script actions are done under a real-user id. I manage this by adding the script path with `sudo visudo` command.
Actually the script is started under a real user credential, not under apache user credential.

I think you can launch from your script a subprocess (with `system` call, and the parameter to that system call should be something like: sudo USER CMD)

Hope it helps
# 3  
Old 01-16-2008
Another way to do it is i.e if you want to change to the user to the owner of the file then you can use 's' bit. i.e the setuid bit on the file. So the executable when it runs , runs as if the owner of the executable is running it
# 4  
Old 01-17-2008
Thanks,

I'll try the same... Smilie
# 5  
Old 01-17-2008
Quote:
Originally Posted by dhanamurthy
Another way to do it is i.e if you want to change to the user to the owner of the file then you can use 's' bit. i.e the setuid bit on the file. So the executable when it runs , runs as if the owner of the executable is running it

I highly recommend against doing this. This is a very bad for security and avoid it at all costs. Some systems like AIX will ignore the setuid bit on a shell script. Use a sudo like solution.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change user

Hi All, need your assistance, how can i change user again after i change my user. here is the code that i tried su - myuser #success su - webuser ##what i want to try is to change user again to webuser from myuser account my output is it cannot change to webuser account. only in... (8 Replies)
Discussion started by: meister29
8 Replies

2. Red Hat

Runtime Error Enable user directory apache

Hi I am exactly according to this link CentOS 6 - Apache httpd - Enable Userdir : Server World I Enabled userDirectory Server version: Apache/2.2.15 CentOS release 6.8 (Final) But Iget this Error Forbidden You don't have permission to access /~mn/index.html on this server Goal... (2 Replies)
Discussion started by: mnnn
2 Replies

3. Shell Programming and Scripting

Passwordless sftp using a different user than the runtime user

I am running a shell script as user A. In that script I need to execute a sftp that would transfer the file using another user B. I am using the below command: sftp -oPort22 B@remote server However, I am getting password prompts each time. I have done the following: Added the public... (4 Replies)
Discussion started by: mady135
4 Replies

4. AIX

How to change normal user id to LDAP user id?

If I create a new user id test: mkuser id=400 test then I want it to LDAP user: chuser -R LDAP SYSTEM=LDAP registry=LDAP test It shows: 3004-687 User "test" does not exist. How to do? (4 Replies)
Discussion started by: rainbow_bean
4 Replies

5. Solaris

how to change /export/home/user dir to /home /user in solaris

Hi all i am using solaris 10, i am creating user with useradd -d/home/user -m -s /bin/sh user user is created with in the following path /export/home/user (auto mount) i need the user to be created like this (/home as default home directory ) useradd -d /home/user -m -s /bin/sh... (2 Replies)
Discussion started by: kalyankalyan
2 Replies

6. Shell Programming and Scripting

Change user

Hi, I have to change many times user in a script. With the command su userName I receive the request for password. I need to open a session with another user I would put the password at the beginning. How can I do it? Thanks, bye bye. ---------- Post updated 22-04-10 at 10:58 AM ----------... (9 Replies)
Discussion started by: abdujaparov
9 Replies

7. UNIX for Dummies Questions & Answers

change user> to user@host> ssh prompt

Hi, I was wondering how to change the prompt for my ssh login. At the moment it is like user> while I'd like it to be as user@host> It is in the .bash_profile or .ssh ??? Thanks (2 Replies)
Discussion started by: pmasterkim
2 Replies

8. Shell Programming and Scripting

How do i change to super user then revert back to ordinary user ,using shell script?

Hi all, I am trying to eject the cdrom from a livecd after certain stage... Now assuming that it is possible to eject,please consider my issue!!! The OS boots into a regular user by default...so i am unable to use the eject command to push out the drive... However if i try pfexec eject it... (3 Replies)
Discussion started by: wrapster
3 Replies

9. UNIX for Dummies Questions & Answers

How to link to some lib in runtime as a nonsuper user?

My program is written in cpp and it uses a non standard library. I have compiled successfully by linking it to the library. But when i try to run the program. it give a error message like: "error while loading shared libraries: ***.so: cannot open shared object file: No such file or directory"... (2 Replies)
Discussion started by: zzz_zzz
2 Replies
Login or Register to Ask a Question