I want to automate
sudo su - user
from a script. It should then ask for a password.
The easiest way is to make it so that user doesn't have to type a password at all.
You can do that by running
However if it's just for one script, it would be more secure to restrict passwordless access to only that script, and remove the
I will try and guess what you asked.
If you want to use
Then put into the script:
Doing just this, won't get subsequent commands get run by
And in sudoers file:
Obviously, a more generic line like:
Will get things done, but would grant the permission to do anything as anyone.
You can use command
(Of course without [ and ])
Please note that you should protect your script from read access from unauthorized users. If you want to read password from separate file, you can use
(Or whatever is the name of password file, containing password and single line break.)
From sudo man page: