How to execute shell script via sudo user

Can someone give an example of running shellscript via user sudo?

I tried like this.

sudo / usr / local / sbin / deploy | ./tmp/cp1.sh

The above script is executed as a regular user, not as a sudo user.

+3
source share
2 answers

Using this command, a deployscript is executed as root , but the ./tmp/cp1.shscript is launched by the current shell under your current privileges. To avoid this, you can prefix sudo for both:

sudo /usr/local/sbin/deploy | sudo ./tmp/cp1.sh

Or you can create a shell from sudo, so the shell is already running as root:

sudo sh -c '/usr/local/sbin/deploy | ./tmp/cp1.sh'
+6
source

, , , sudo sudoers, . gksudo ( sudo), , , .

0

Source: https://habr.com/ru/post/1723009/


All Articles