0

I am logged in as root user and need to execute a single command from redbox user without switching. For this, I am using following command:

# su - redbox -c 'CMD'.

When I try to execute "ifconfig" (su - redbox -c 'ifconfig'), I get following error:

-bash: ifconfig: command not found

But it works if I switch to redbox first, and then execute "ifconfig" as shown below:

# su - redbox $ ifconfig

Same problem for many more commands. I don't understand what is causing this problem. Please help me figure it out.

I am using Alpine Linux v3.9.4

UPDATE:

Thanks to link shared by Jeff, I see the problem now. When I use su - redbox - c 'ifconfig', the value of $PATH is different than when I use su - redbox followed by ifconfig.

Can someone explain why $PATH is different in both cases? Note that in both cases I hove used - which uses login shell.

8
0

Read man sudoers. sudo forces its idea of $PATH on the commands it executes.

sudo -u redbox -c $( type -p ifconfig) 

to use your $PATH or

sudo -u redbox /usr/sbin/ifconfig
1
  • 1
    I am not using sudo though. – Niraj Joshi Dec 19 '19 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.