Shell script that changes user
I want to write a shell script that switches user runs another script and then exits the user account.
The only problem I am having is that the script askes for the password but I want the password to be in the script (the script will be execute only so the user will not be able to see the password).
A script like this is probably not a very good idea. Perhaps you'd like to mention what it is you're trying to accomplish and a suggestion can be made.
If you're hell-bent on doing it like this, it's probably easiest to setuid the script to run as root, in which case "su username" will not prompt for a password.
Re: Shell script that changes user
Quickes, easiest, least messy, and least security compromising way to do this is with SUDO. it should already be installed on your system, if not it's pretty easy to add. Use the command 'visudo' to edit the configuration.
You'll need to add a command alias:
And you'll need to add a line for the user to run this script
userName ALL=(userToRunAs) NOPASSWD: SOMECOMMAND
Then in your script to execute the command as the other user just write the command as:
sudo -u userToRunAs /path/to/the/script
|All times are GMT -5. The time now is 10:31 PM.|