I recently started to learn about linux Command operations and encountered problems when I used the 'useradd' command. I want to add a username command named user1, which should be 'useradd user1', but the prompt "bash: useradd: command not found" appears, finally, I found the reason for checking the information on the Internet.
First, I did not log on to the root user, but logged on to the common user. Then I switched to the root user using the 'su root' command, so this is the problem.
The 'su root' command only changes the root permission and does not change the environment variables. 'Su-root' can obtain the permissions and environment of the root user.
Make corrections now:
Bash-3.2 $ su-
Password:
[Root @ xudonglee ~] # Pwd
/Root
[Root @ xudonglee ~] #
The following is the root environment variable in this case:
/Usr/lib/qt-
3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin
:/Usr/sbin:/usr/bin:/root/bin
The following is the root environment variable when I simulate "su" again.
/Usr/kerberos/sbin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin
It should be clear now that although the two names are converted to the root user, their effects are different, so it is best to directly use the "Su-" command in the future. Although the "Su" command is easy to use, if you need to use environment variables, we need to change them again.
I recently started to learn about Linux Command operations and encountered problems when I used the 'useradd' command. I want to add a username command named user1, which should be 'useradd user1', but the prompt "Bash: useradd: Command not found" appears, finally, I found the reason for checking the information on the Internet.
First, I did not log on to the root user, but logged on to the common user. Then I switched to the root user using the 'su root' command, so this is the problem.
The 'su root' command only changes the root permission and does not change the environment variables. 'Su-root' can obtain the permissions and environment of the root user.
Make corrections now:
Bash-3.2 $ su-
Password:
[Root @ xudonglee ~] # Pwd
/Root
[Root @ xudonglee ~] #
The following is the root environment variable in this case:
/Usr/lib/Qt-
3.3/bin:/usr/Kerberos/sbin:/usr/Kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin
:/Usr/sbin:/usr/bin:/root/bin
The following is the root environment variable when I simulate "Su" again.
/Usr/Kerberos/sbin:/usr/lib/qt-3.3/bin:/usr/Kerberos/bin:/usr/local/bin:/usr/bin
It should be clear now that although the two names are converted to the root user, their effects are different, so it is best to directly use the "Su-" command in the future. Although the "Su" command is easy to use, if you need to use environment variables, we need to change them again.