my user is not root in the machine. when I run :
sudo su - user2
I switch to the user2 without password prompt.
when I run
sudo su - user2 < file_contains_commandLines
I can run the commands in the file "file_contains_commandLines" as the user user2 - also without typing my password
However when I run
sudo -u user2 ls
or
sudo su - user2 -c "ls"
I should enter my password and i got
Sorry, user myUser is not allowed to execute '/bin/ls' as user2 on machinexyz.
How can I pass the list of command to be executed as the user2 without having to enter my password ... since I can run sudo su - user2!
I want to avoid to pass my commands via a document as follow:
sudo su - user2 < file_contains_commandLines