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.
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):