Linux user Profile Management and Environment Variable
Linux uses the /etc/profile, /etc/profile.d/*, ~/.bash_profile, /etc/bashrc, ~/.bashrc, ~/.bash_logout, and /etc/skel/* files to manage user profiles, system-wide functions, and aliases. This tutorial explains how the shell interprets and uses these files to set and manage user profiles, aliases and environmental variables.
The /etc/profile
It is a default user profile file. It is the first file Linux executes each time when a user logs in. It contains environment variable definitions the system needs to provide a default profile for each user. It sets default environment variable definitions for all users. Since it is part of the default installation, the update process can overwrite it when an update is available. The appropriate path to add a custom environment variable is /etc/profile.d directory. Create a custom.sh file in this directory and use it to add custom environment variables for all users.

The ~/.bash_profile file
The shell executes this file after the /etc/profile file whenever a user logs in. Its default settings are straightforward. It launches the .bashrc file and initiates the custom environment variables defined in it. It is a user-specific file. An environment variable defined in this file remains available only for the user.

If you want to define an environment variable permanently, add that at the end of this file. If you add a custom variable, you must export it. Let us take an example.
- Run the echo $HISTSIZE to view the value of the default history size environmental variable. The default is 1000.
- Open the ~/.bash_profile file and add the following lines at the end of the file.
HISTSIZE=20 export HISTSIZE
Save the file. Shell will reread this file at the next login. Til then, it uses the old value. Run the echo $HISTSIZE command to verify it.

Terminate the current session and log in again. Verify the updated value of the $HISTSIZE.

The ~/.bashrc file
This file defines functions and aliases. It is a local user-specific file. It first executes the default /etc/bashrc file. Then, provide a section to add custom functions and aliases. Any custom function or alias added to this file remains available only to the user.

The /etc/bashrc file
Like the /etc/profile file, the /etc/bashrc is also a global user profile file. It defines the system-wide global functions and aliases. Any change made to this file remains available for all users. Similar to the /etc/profile, directly editing this file is not recommended. Any change made to this file might lost at the next software update. If you want to add a custom function or alias, create a custom.sh file in the /etc/profile.d/ directory and add it to that file.

The ~/.bash_logout file
Shell runs this file when the user logs out. By default, it contains nothing. You can customize this file to show a custom message or run specific commands for logging and monitoring purposes. It works only when the user logs out on the CLI prompt. It has no effect if the user logs out on the GUI prompt.

Execution of profile files
The following image shows the conceptual layout of the shell's sequence to execute profile files when a user logs in.

The *profile v/c *rc files
The rc files are for all shell invocations, while the profile files are strictly for interactive shells. The profile files do not run when the shell is executed in non-interactive mode.
Local v/c global configurations
| Global | Local |
| The /etc/profile and /etc/profile.d/* files globally define environmental variables for all users. An environmental variable added to these files remains available for all users. | The ~/.bash_profile file locally defines environmental variables for the particular user. An environmental variable added to this file remains available only for the user. |
| The /etc/bashrc and /etc/profile.d/* files globally define functions and aliases for all users. A function or an alias added to these files remains available for all users. | The ~/.bashrc file locally defines functions and aliases for the user. A function or an alias added to these files remains available for the particular user. |
Updating/modifying global files
The contents of the the /etc directory are global for all users. They are update candidates. When we update a package or packages, the update process overwrites the related contents in this directory. It wipes out all our custom settings and configurations. To avoid it, use the shell override method. This method keeps all custom settings and configurations in a separate directory. The update process never touches the settings and configurations outside the default package paths. If custom settings and configurations are available, the shell uses them instead of the defaults in the /etc directory. It allows us to use custom settings and configurations for any package without worrying that the next update might remove them. Linux keeps custom settings and configurations related to user profiles, custom functions, aliases, and environmental variables in the /etc/profile.d directory. Use this directory to deploy custom settings or override default configurations.
The /etc/skel directory
The /etc/skel directory contains default user profile files (.bash_profile, .bashrc, and .bash_logout). When we add a new user account, the shell copies these files from this directory to the user's home directory. If we change profile files in this directory or add a new profile file, new user accounts get the updated files with the newly added custom profile file. However, it does not affect existing user accounts. They keep using their existing files.

This tutorial is part of the tutorial series 'User profile files, environmental variables, and aliases in Linux'. Other parts of this series are the following.
Chapter 01:- Linux User Profile Management and Environment Variable
Chapter 02:- Linux Environment Variables List, Set, Create & Remove
Chapter 03:- Linux alias List, Set, Create & Remove with alias Command
Key points:-
- Linux uses a series of files to set environmental variables, functions, and aliases.
- It uses the /etc/profile, /etc/profile.d/*, and ~/.bash_profile files to set environment variables.
- It uses the /etc/bashrc, /etc/profile.d/*, and ~/.bashrc files to set functions and aliases.
- The /etc/profile and /etc/bashrc files save default values for environmental variables and definitions for system-wide functions and aliases.
- The /etc/profile.d/ directory saves custom script files for user-defined environmental variables and definitions for system-wide functions and aliases.
- The /etc/skel directory contains default .bash_profile, .bashrc, and .bash_logout files.
- When we add a new user account, the creation process copies these files from this directory to the user's home directory.
- If we change or update default files in the /etc/skel directory, changes affect only new users.
Conclusion
Linux includes many shells with the default installation. Different shells use different profile files. The bash shell is the default. It uses the /etc/profile, /etc/profile.d/*, ~/.bash_profile, /etc/bashrc, ~/.bashrc, ~/.bash_logout, and /etc/skel/* files to manage user profiles, environmental variables, functions, and aliases. In this tutorial, we explored these files and learned how the bash shell processes them when a user logs in.
By ComputerNetworkingNotes Updated on 2026-06-03