How to run the command from another Linux user?

Good afternoon.
There is a Linux (CentOS 7). This Linux has two standard user - "user1" and "user2".
There is a script located here: "/home/user2/scripts/script1.sh".
User1 can execute this script by running the command: "su user2 /home/user2/scripts/script1.sh" while the console will prompt for a password from user2.
The password I know, but how can I add this password in the command to run immediately, without prompting for a password?
Found a version of "su user2:password /home/user2/scripts/script1.sh" but it's not working, says things like "su: user user2:password does not exist".
Tell me how to overcome?
April 4th 20 at 13:19
5 answers
April 4th 20 at 13:21
Solution
$echo <password> | sudo-S <command>
And what's the name of the user to insert, from which I want to run? - Wilbert commented on April 4th 20 at 13:24
@Wilbert,
echo <password> | sudo -u <user> -S <command> - Isobel2 commented on April 4th 20 at 13:27
@Wilbert, damn you dokumentaciju taught Chet ??
user: test
password: test22
$ echo test22 | su -l test-c id
uid=1005(test) gid=1005(test) groups=1005(test)
- Kristoffer_Beahan commented on April 4th 20 at 13:30
@Isobel2, Thanks, but your variant does not work: "$ echo password | sudo -u user2 -S /home/user2/scripts/script1.sh"

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for user1: Sorry, try again.
[sudo] password for user1:
sudo: 1 incorrect password attempt
You have new mail in /var/spool/mail/root" - Wilbert commented on April 4th 20 at 13:33
@Kristoffer_Beahan, unfortunately, I was taught only to read.
Thanks for your version, it works. - Wilbert commented on April 4th 20 at 13:36
@Wilbert, do not confuse sudo and su damn.
sudo reads the password only terminal . for the GUI there is an option with askpass.
but su can read the password from stdin - Kristoffer_Beahan commented on April 4th 20 at 13:39
April 4th 20 at 13:23
to use sudo.
in the config file /etc/sudoers to prescribe the necessary commands to run as another user without password prompt.
This is not an option, unfortunately. - Wilbert commented on April 4th 20 at 13:26
@Wilbert, if you don't fit the standard UNIX way of solving problems, you probably have problems in the architecture of your solution, and if the case concerns the rights of access and security. - Maegan_Ankunding26 commented on April 4th 20 at 13:29
@Maegan_Ankunding26old as shit mammoth system which can not sudo... common situation. - Kristoffer_Beahan commented on April 4th 20 at 13:32
April 4th 20 at 13:25
man sudo

There's just some incredible opportunities. Not sure how for normal user, but for root (run the program from root without password prompt) like this:
# Nagios Remote Plugin Executor priviegion
nrpe ALL=(ALL) NOPASSWD: /usr/lib64/nagios/plugins/
April 4th 20 at 13:27
SUID, SGID
Like, the script is not valid. Just for binaries. - Angel_Stanton commented on April 4th 20 at 13:30
@Angel_Stanton, and then the binaries?
You can reference?

There is a race condition inherent to the way shebang (#!) is typically implemented:
actually you need to do sleduushee
1. put the file in for example /bin ( here are the options available)
2. name it as going to run scrypt for example
3. Give it permission to run , and additional rights
4. gland and enter the interpreter in petway line of the file.
5. make sure that the interpreter is in the system, because this sh it is.
Actually all.
well - antoinette_Stokes commented on April 4th 20 at 13:33
@antoinette_Stokes, no Link - I tried to set the SetUID on the script, did not work. Can, since changed...
The easiest way is really to check.

Appallingly ignorant of the text does not gives me confidence. The reference to "race condition" here is clearly not on. - Angel_Stanton commented on April 4th 20 at 13:36
April 4th 20 at 13:29
Thank you to all of solution found: "$ echo password | su -l user2 -c /home/user2/scripts/script1.sh"
Suddenly someone come in handy.
Caution - the password will remain in the command history shell. - Angel_Stanton commented on April 4th 20 at 13:32
A very good decision.
su != sudo - wyatt commented on April 4th 20 at 13:35

Find more questions by tags LinuxCommand line