Answer the question
In order to leave comments, you need to log in
How to run a command as a different Linux user?
Good afternoon.
There is Linux (CentOS 7). There are two regular users on this Linux - "user1" and "user2".
There is a script that is located here: "/home/user2/scripts/script1.sh".
User1 can run this script by executing the command: "su user2 /home/user2/scripts/script1.sh", which will prompt the console for user2's password.
I know the password, but how can I add this password to the command so that it runs immediately, without asking for a password?
Found the option "su user2:password /home/user2/scripts/script1.sh", but it doesn't work, says like this "su: user user2:password does not exist".
Tell me how to overcome?
Answer the question
In order to leave comments, you need to log in
use sudo.
in the /etc/sudoers config, write the necessary commands to run from another user without asking for a password.
man sudo
There are some incredible possibilities there. I don’t know how for a regular user, but for root (running the program from root without asking for a password) is done like this:
# Nagios Remote Plugin Executor priviegion
nrpe ALL=(ALL) NOPASSWD: /usr/lib64/nagios/plugins/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question