0

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
  • Does sudo su - user2 -c "ll" work? I know ls isn't valid on any of my servers when using sudo. I'm sure there is a reason but I can't be bothered figuring it out as it isn't a big issue for me. However, if ll works for you it might point you in the right direction. – Admiral Noisy Bottom Apr 30 '20 at 03:43
  • not working as well, same result : it demands my password (it shouldnt) and it says : Sorry, user myuser is not allowed to execute '/bin/su - user2 -c ll' – Mohamed Taboubi Apr 30 '20 at 03:45
  • https://serverfault.com/a/160587/200560 – Jacob Evans Apr 30 '20 at 03:54
  • 2
    Does this answer your question? [How to setup passwordless \`sudo\` on Linux?](https://serverfault.com/questions/160581/how-to-setup-passwordless-sudo-on-linux) – Jacob Evans Apr 30 '20 at 03:54
  • I modified one of my /etc/sudoers on a server and was able to run sudo commands without a password. Jacob's link also confirms it https://serverfault.com/questions/160581/how-to-setup-passwordless-sudo-on-linux/160587#160587 – Admiral Noisy Bottom Apr 30 '20 at 04:25
  • You have only configured passwordless sudo to the root user. With your first command you execute the command "su - user2" as user root. The root user can su to any user without password. – Alexander Worlitschek Apr 30 '20 at 14:23

0 Answers0