The usermod command successfully through sudo.

sudo usermod -aG some_group some_user

However, if you execute it through su, then there will be an error.

...I enter root password...
usermod -aG some_group some_user
bash: usermod: command not found

Why it happens?

How to configure my system?

The fact is that I have a script that I cannot change. This script uses command usermod under su.


su loads profile from /etc/profile which may modifies shell $PATH variable.

man su says

-m, -p, --preserve-environment
              Preserve the entire environment, i.e., it does not set HOME,
              SHELL, USER nor LOGNAME.  This option is ignored if the option
              --login is specified.

so, use --preserve-environment flag to load $PATH from existing shell

su --preserve-environment

manually export PATH variable

export PATH=$PATH:/path/of/usermod/dir
| improve this answer | |

You need the $PATH setting for root. That is no problem with sudo because it has its own $PATH.

su does not change $PATH by default. You have to make it start a login shell:

su -

instead of just


If you cannot change the su call then change $PATH before the call. If usermod is located at /usr/sbin/usermod then do this:

| improve this answer | |

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.