superuser without prompting for pswd.

I have a korn shell script (main.sh) owned by unix account "A". I want to execute certain lines in the script using another user "B" (with user "B" login profile). I need to do this way for multiple lines to be executed using different unix accounts in main.sh.

I was trying to use "su - <account>" but it prompts me for password in interactive mode. How do I write main.sh script that executes various commands by logging in as different accounts and login profiles. Is there a way to automatically redirect the password for "su" command to accept the password.

Unix is Sun Solaris.

You cannot.

No. (Well, there's a way, but it's the wrong solution.)

  1. Install the sudo package, available at the Blastwave site.
  2. Run visudo (as root) and configure your user to run the script with the NOPASSWORD option:
    text ashok ALL=(root) NOPASSWD: /full/path/to/main.sh
  3. Run it as "sudo /full/path/to/main.sh"

Here's an excellent link describing uses of sudo.

A method which will usually work if you have a default TCP/IP setup with rlogin and remsh enabled. This approach is a security risk but less dangerous than holding a password in a script. All access will be logged. Don't do this with a root account.

See:
man inetd
man .rhosts

To give user user1 full access to user2.

Under user2 home directory create (or edit) the file called .rhosts with permissions 600 owned by user2.
In the .rhosts file put the line:

localhost user1

Then user1 can then rlogin to account user2:

rlogin localhost -l user2

Also user1 can run commands as user2 using remote shell (the command name for remote shell varies according to unix version):

remsh localhost -l user2 env

remsh localhost -l user2 -n "pwd;ls -la"

Alternatively, you can use the supported pfexec/rbac.

RBAC - Role Based Access Control at OpenSolaris.org