2
  • For example: I installed ifconfig
  • First i become root with "su"
  • Now I write "ifconfig" and get: "command not found".
  • I write "sudo ifconfig" and now it works.

This seems to happen with a lot of programs (not all).

Another example: apt-get does not seem to properly install applications if I'm not using the same method.

I should not need to write sudo if I'm already root.

Why is that? What can I do to fix this?

3 Answers 3

5

TL,DR: Use su --login or sudo.


Debian sets a different PATH for regular users. In /etc/profile, you can see that the defaults reserve /sbin for root:

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH

type ifconfig says the utility resides at /sbin/ifconfig which is why regular users can't access it easily. When you run su with no arguments, the calling user's environment is preserved, including the PATH variable. sudo, on the other hand, provides a fresh environment and overrides the calling user's PATH.


The reason why you believe su is malfunctioning is because resetting PATH and IFS by default is legacy behavior. buster recently switched to the util-linux implementation of su which works differently; see /usr/share/doc/util-linux/NEWS.Debian.gz for details.

1
  • 1
    Or simply /sbin/ifconfig without sudo nor su
    – GAD3R
    Sep 7, 2018 at 16:10
0

As dsstorefile1 said, the behaviour was changed.

Either you run "su -" instead of "su" or you could

add "ALWAYS_SET_PATH yes" to "/etc/login.defs" to preserve old Debians behavior.

0

use su - root instead of su root. Then type adduser username sudo

1
  • 2
    Welcome to Super User! Can you edit your answer and explain why OP should do this?
    – bertieb
    Jul 7, 2019 at 16:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .