Ensure That The User PATH Variable Is Properly Defined
In Linux systems, the PATH variable defines the search paths for executable files within the current user context. For example, when a user executes the ls command from any directory, the system searches for the corresponding executable within the directories specified by PATH and runs it once located. The PATH variable across all user contexts must not contain the current directory (.). Furthermore, the directories specified by PATH must exist as valid, real paths within the filesystem and align with the system's design expectations. A valid PATH value effectively prevents system commands from being replaced by malicious binaries, thereby ensuring secure command execution.
The default PATH configuration in openEuler OS is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin. You can modify PATH based on your specific scenarios, but it must be valid.
- You can run the echo command to verify the current PATH value within the current user context and ensure it is properly configured.
- The PATH value in the openEuler root user context is as follows:
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
- The PATH value in an openEuler regular user context (using the test user as an example) is as follows:
echo $PATH
/usr/local/bin:/usr/bin
- The PATH value in the openEuler root user context is as follows:
- To modify PATH, proceed with the following methods.
The PATH environment variable can be configured at two levels: system-wide configurations within /etc/profile which affect all users, and user-specific configurations within .bashrc or .bash_profile located in the user's home directory, which affect only the current user. Modifying the PATH-related configurations in these files allows you to change the system PATH value either permanently or temporarily.
- Method 1: Permanent modification via configuration files (using /etc/profile as an example)
- Open the configuration file.
vim /etc/profile
- Press i to enter the insert mode and change the PATH value.
export PATH=$PATH:<attach new path> // attach new path: Add a new path.
- Press Esc to exit the insert mode. Type :wq! and press Enter to save the file and exit.
- Open the configuration file.
- Method 2: Temporary modification for the current session (automatically expires after the session closes)
export PATH=$PATH:<attach new path> // attach new path: Add a new path.
- Method 1: Permanent modification via configuration files (using /etc/profile as an example)