In my last article I had shared the instructions which can be used to check the path of any command on your Linux machine so that you do not end up with this error
Most of you must have been facing this issue. Actually this can not be considered as as error until and unless the package file for the command is missing or has corrupted due to some reason because in that case you might have to re-install the package.
# useradd deepak
-bash: useradd: command not found
# whereis useradd
useradd: /usr/sbin/useradd /usr/share/man/man8/useradd.8.gz
# which useradd
/usr/sbin/useradd
You can use find command ultimately to look out for the missing command or file (As all the command are executable files)
# find / -name useradd -type f
/usr/sbin/useradd
So now once you got the location of the command, add the path to the PATH variable
But again running this export command will be session dependent so once you change the session you will again have to export the new PATH variable
# vi /root/.bash_profile
export PATH=/usr/sbin:$PATH So now every time your system reboots this command will be executed and the PATH variable will be updated.
Permanent Fix:
To fix this issue permanently so that this issue does not comes up again. You can add the default location of all the directories in the PATH variable which contains all the executable files in Red Hat Linux in your .bash_profile file.
You should also read the difference between .bash_profile and .bashrc, so that you can use the file wisely?
NOTE: The following commands are tested on RedHat and CentOS
First find the full path of the executable file using the below command or any of the command shown above
# which useradd
/usr/sbin/useradd
Solution 1
Then run the below command
$ rpm -qf /usr/sbin/useradd
shadow-utils-4.0.17-15.el5
As you see the package responsible for useradd binary file is shadow-utils
Solution 2
# yum whatprovides */useradd
2:shadow-utils-4.1.4.2-13.el6.i686 : Utilities for managing accounts and shadow
: password files
Repo : base
Matched from:
Filename : /etc/default/useradd
Filename : /usr/sbin/useradd
# yum -y install shadow-utils