Skip to content

Linux User Profile (profile)

Adjusting Users’ Desktop Environment on Linux

During a user’s login process, when the bash shell starts, it executes some scripts to set the profile. These scripts can be customized and different in each Linux distribution. Its function is to configure some environment variables and tune the system for users.

To adjust the User Profile on Linux, bash reads the configuration from several files. The content of these files may vary from distribution to distribution, and a distribution does not always use them all, but the general idea remains.

Bash also searches for the /etc/bash.bashrc file, which also has a function similar to profile, but bashrc is executed every time bash is executed.

Each user can also create their own startup scripts to be executed during login. These files must be located in the users’ home directory with the names:

  • .profile
  • .bash_profile
  • .bash_login
  • .bashrc
  • .bash_logout

The dot “.” before the file name gives it the hidden attribute and is only listed with the command “ls —lga”.

Bash Profile Files

Bash allows functions, variables, and nicknames to be written to some files so that they can be loaded again when the system is restarted, or a new bash execution takes place.

The files read by bash are:

/etc/profile

Global Profile configuration file for all users. Defines global variables and is executed during the user authentication process. This script also usually loads the files contained in the /etc/profile.d directory with the source command.

/etc/profile.d

This directory contains one or more scripts that are loaded by /etc/profile.

$ ls -l /etc/profile.d -rw-r--r-- 1 root root 1606 Jul 31 2018 colorls.sh -rw-r--r-- 1 root root 2703 Aug 2 2018 lang.sh -rw-r--r-- 1 root root 121 Jul 31 2018 less.sh -rw-r--r-- 1 root root 248 Jul 17 14:46 vim.sh

/etc/bashrc or /etc/bash.bashrc

Global Profile configuration file, which defines important variables and runs every time Bash is loaded. In some distributions it appears under the name /etc/bashrc and in others as /etc/bash.bashrc.

~/.bash_profile

Individual profile file for each user that is immediately executed at /etc/profile. Its content is read with each execution of Bash and each user has their own in the HOME directory.

~/.bash_login

If the file ~/.bash_profile does not exist, it is executed immediately after the login process. Each user has their own;

~/.profile

If the .bash_profile and .bash_login files don’t exist, it runs immediately after login. Each user has their own;

~/.bashrc

It runs automatically when the Bash process is started. Each user has their own;

~/.bash_logout

It is executed during the logout process;

Remember that the “~/” indicates the HOME directory of the logged in user.

You might want to look at these files and analyze their content. Each distribution may; vary the content of these scripts. You might even notice that one script calls the other.

It is very important to know the function and when each file is executed. In general, keep in mind that:

  • The files in the /etc directory are global and are valid for all users; The files in
  • the HOME directory are individual for each user;
  • The files with a profile in the name are uploaded to login process, one-time;
  • Files with bash in the name are loaded every time Bash is executed.

Another important detail is that these files are read and executed in the order described above: first Profiles, then Bash. Not all distributions make use of all of these files.

The default order of the loading process of these scripts:

  1. Run the content of /etc/profile
  2. Run content of files located at /etc/profile.d/*
  3. Run .bash_profile in user home folder
  4. Run .bash_login in user home folder
  5. Run .profile in user home folder
  6. Run the shell process indicated in /etc/passwd for that user
  7. If the shell is “bash”, run the /etc/bashrc script
  8. if the shell is “bash”, run the .bashrc in user home folder

The ~/.bashrc script is loaded every time bash is executed. And the ~/.bash_logout script every time Bash terminates.

It’s common in some distributions missing some profile files. Each distribution adopts variations of this default profile schema.