Non-interactive user switch to root

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Non-interactive user switch to root
# 1  
Old 11-19-2007
Non-interactive user switch to root

Is is possible switch user from a non-root user to root user without entering the password interactively inside a korn shell script which is run by a non-root user?

e.g. I have a non-root user called infodba who is in dba group and I want to create a shell script which is executed by infodba user and inside the script I want to switch to root user without getting prompted for the password and run chmod 777 command against a directory then switch back to infodba and create a file inside the directory. I like to perform the below in one script run by infodba without getting prompted for password.

(1) TEST_DIR exists with the access below
ls -ld TEST_DIR
drwxrwxr-x 2 root sys 80 Nov 20 10:45 TEST_DIR

(2) Give full access to TEST_DIR by root
chmod 777 TEST_DIR
ls -ld TEST_DIR
drwxrwxrwx 2 root sys 80 Nov 20 10:46 TEST_DIR

(3) Create a file inside TEST_DIR using infodba
touch TEST_DIR/test.txt


Unix version : HP-UX 11.11
# 2  
Old 11-19-2007
sudo looks like the tool for you (or RBAC if HPUX supports it).

BTW, I would suggest that you don't set world permisions If you absolutely must give world permissions (and there's hardly ever a good time to do this), the sticky bit to protect the files within it.
# 3  
Old 11-19-2007
I agree that you need sudo. This way you don't need to switch user, you can give that user permissions to run xxx program with yz switches. The command then turns into

sudo chmod 777 /some/directory

This prevents that user from running it with any other perms and allows you to keep the root password sacred.

Here it is from the software porting place:

You'll need to edit the config file.

# 4  
Old 11-20-2007
Smiling Dragon,
Thanks for your advice.

Is there a way to do this only using standard HP-UX commands without using any tools?

# 5  
Old 11-20-2007
Sorry, I'm not familiar enough with HPUX to know, sudo is widely used though (and is included with some unix distributions) , you don't need to fear that it's too wierd or unsupported for use in an enterprise environment.
# 6  
Old 11-20-2007
You can download Sudo from HP rather than going outside. It's in the HP-UX Internet Express for HP-UX 11i v1 product, available off Hewlett-Packard Co..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Switch from Local user to root user from a shell script?

Hi, I need to switch from local user to root user in a shell script. I need to make it automated so that it doesn't prompt for the root password. I heard the su command will do that work but it prompt for the password. and also can someone tell me whether su command spawns a new shell or... (1 Reply)
Discussion started by: Little
1 Replies

2. Shell Programming and Scripting

How to switch user in shell scripting (without root)?

Hi everyone: I need create a script that must switch user and then must execute certain commands, sadly neither my user nor the second user have no privileges for su - , I've tried everything but seems su doesn't accept input redirection, please help me, ... (4 Replies)
Discussion started by: ooilinlove
4 Replies

3. Shell Programming and Scripting

Switch between root and user in the same script.

I am writing a korn shell script where i need to switch to root in between and again exit from root to normal user and continue other commands. Is that possible to switch between these two in the same script? (1 Reply)
Discussion started by: santosh2626
1 Replies

4. UNIX for Dummies Questions & Answers

Not able to switch to other users using su -user from root

Hi all, I have a small problem. When I log in as root and try to switch to any other user using su -user, then it is giving an error saying permission denied. Can you help me? Thank you in advance. Sai. (1 Reply)
Discussion started by: sai2krishna
1 Replies

5. Solaris

Unable to switch back to root from user

Hi, I am new to Solaris and when i am trying to Switch to root login from user, system throws message saying permissions denied... Steps I Followed: Created a user and logged into that user by SU username tried to come back to root but system throws message "permissions denied" ... (7 Replies)
Discussion started by: VijaySolaris
7 Replies

6. UNIX for Dummies Questions & Answers

Sudo to delegate permission from non-root user to another non-root user

I've been through many threads before i decide to create a separate thread. I can't really find the solution to my (simple) problem. Here's what I'm trying to achieve: As "canar" user I want to run a command, let's say "/opt/ocaml/bin/ocaml" as "duck" user. The only to achieve this is to... (1 Reply)
Discussion started by: canar
1 Replies

7. Shell Programming and Scripting

switch user from local user to root in perl

Hi Gurus, I have a script that requires me to switch from local user to root. Anyone who has an idea on this since when i switch user to root it requires me to input root password. It seems that i need to use expect module here, but i don't know how to create the object for this. ... (1 Reply)
Discussion started by: linuxgeek
1 Replies

8. Shell Programming and Scripting

Switch to different user without expect

Hi, I have to switch to a different user and execute certain commands and then come back to the original user Ex: My id is 'usstage'. I need to switch to 'apstage', souce a script there, execute a function and then get back again to usstage. Please note that I do not have expect installed... (4 Replies)
Discussion started by: sugan
4 Replies

9. UNIX for Dummies Questions & Answers

How to allow access to some commands having root privleges to be run bu non root user

hi i am new to unix and i have abig task. i have to \run particular commands having root privileges from a non root user. i know sudo is one of the way but i need sum other approach kindly help Thanks (5 Replies)
Discussion started by: suryashikha
5 Replies

10. Shell Programming and Scripting

SFTP- Non-interactive user authentication

Hi All, sftp -b script.txt <hostname> user-authentication through non-interactive way is desired. But, its failing to do so. Could anyone kindly advise. Thanks for any/all help at the earliest. Regards, Dheeraj. (1 Reply)
Discussion started by: dheeruchakri
1 Replies
Login or Register to Ask a Question