Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a shell script to start a server program.  start

When above command will executes, it will try starts the server as adminuser. To achieve this my script has written like this.

SUBIT="su - adminuser -c "

# Function to start cluster

function start(){



When i execute the command it asks for password. Is there any other way to do this so, it will not ask for password.

I have seen this behavior in Jboss startup script provided on jboss. That script changes the user to jboss and then starts the jboss server. I wanted my script to behave same way.

share|improve this question

migrated from Mar 30 '10 at 13:57

This question came from our site for professional and enthusiast programmers.

up vote 1 down vote accepted

Unless I am missing something what you ask is not possible.

The jboss script is designed to

  1. Start as root
  2. Switch to jboss user which has less privilages

But what you ask is

  1. Start as a non-privilaged user
  2. Switch to admin/root which has more privilages.

This is why you will always need a password no matter the command you try.

Is there any specific reason that your server needs elevated privilages?

share|improve this answer
you mean to say if i run my script from root, it will work as I like it to run? – vijay.shad Mar 30 '10 at 12:28
What he describes is exactly what is given by the setuid bit. – Kevin M Mar 30 '10 at 14:58

If you are root, just use sudo:

$1 sudo -u adminuser start
share|improve this answer
Hi unwind, Can you please describe the command? I think it will su to adminuser and then call the script. Am i right? – vijay.shad Mar 30 '10 at 11:41
sudo, not su (though you can use su too, as su -c, but these are different commands with different purposes). – wRAR Mar 30 '10 at 11:47
Above command still asks for the password? :( – vijay.shad Mar 30 '10 at 12:02
@vijay.shad: The man page I linked (click the command name in my answer) provides plenty of explanation. You really shouldn't be getting a password prompt if you're running sudo as root. Verify that you are. – unwind Mar 30 '10 at 12:18

Like JBoss, you could check to see if you are the target user before running your command.

SUBIT="su - adminuser -c "

# Function to start cluster

function start(){

   if [[ `whoami` == "$TARGET_USER" ]]
share|improve this answer

You could always use the setuid bit. Make the owner of the file the user you want to run the script as and then make your script setuid.

Note that this can be a security risk so make sure that user has only the permissions needed. After all, an unprivileged user can run that script, right?

EDIT: Don't make scripts setuid. Your jboss example is a program that drops privileges, not a script.

share|improve this answer
Most Unix implementations do not allow setuid scripts. See for example . – coneslayer Mar 30 '10 at 14:30
You should never have a script that's setuid and many systems won't allow it. – Dennis Williamson Mar 30 '10 at 14:36
Aah yes--setuid is for programs, not scripts. – Broam Mar 30 '10 at 14:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.