H
H
HeroFromEarth2016-10-25 14:38:23
linux
HeroFromEarth, 2016-10-25 14:38:23

How to pass environment variables when using sudo -u?

Hello.
It is necessary to execute a command like root

envVariable1=15 envVariable2=25 sudo -u user1 sudo -E command

in order for it to be executed not from the root, but from a specific user, and the command needs to pass certain environment variables. As far as I understand, when you run sudo -u user1, the command will have access to the environment variables that user1 has, and not root.
How can I pass the environment variables I need to a command?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
HeroFromEarth, 2017-08-01
@HeroFromEarth

The problem is finally solved like this:
SOMEVAR=123 sudo -E -u user1 sudo -E command

R
romy4, 2016-10-25
@romy4

sudo -u user1 'envVariable1=15 envVariable2=25 sudo -E command'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question