AIX How to run a Shell Script by changing the User

Hi All,

Currently our application is running on the server having AIX 5.3 OS.

What we intend to do is to run a shell script owned by another user and needs to be run as that particular user.

I was trying to create a shell script using the su command before running the actual script (which will be executed from the new script). The su command always prompt for a password. Is there any way we can put that in the shell script so that there is no user prompt.

Also please guide if there is any better methodologies to achieve this.

Thanks

Abhik

Depends on the security policies on your site. One possible solution is to create .rhosts file in the home directory of the secondary user containing only the hostname and username of the calling user, and use:

# assuming remsh is the Remote Shell on AIX
remsh localhost -l loginname -n scriptname
# or alternatively
su loginname -c "scriptname"

I prefer the su version because it is easier to return control to a script.

If you run this as a non-privileged user, then it will ask for the password. AIX has sudo (what you want to use); you must download and install it if it is not already on your system. Someone here with AIX experience can guide you.

I know UNIX, but every time I give a detailed answer to an AIX question I get something not quite right because AIX is, um, different.

Is there no way where we can pass the password as a parameter as how we are passing the user name?

You are doing alright. In fact sudo is one of the few things where AIX is different from "normal AIX", because it is absolutely the same as other systems.

Yes, this is possible. Admins doing this should be tarred and feathered, though. Honestly: you don't want to do this. It is a security hole you can drive a truck through and begs the question: if one user is allowed to know the password of the other user than why can't they share a user-ID anyway?

Keep in mind that shell scripts are plain text - what you write into them can be read with a simple editor. Would you want to put a password simply into a file? You could as well use no password at all instead, no?

Install sudo , which you can download from the IBM AIX Toolbox for Linux Applications as an rpm-package.

Basically you define three things in a sudoers file: a "command alias", which is a list of commands (it can even be one command). Then a "user alias", which is the same for a list of users - it can also be one user. The last thing is a list of things to be allowed: a certain user-alias (the list of users defined there) should be allowed to execute the command-alias (the list of commands) not as themselves but as a certain other user (usually, but not necessarily root).

I hope this helps.

bakunin