Categories: Users and Groups

Linux User Profile (profile) [Basic Guide]

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.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Share
Published by
Uirá Endy Ribeiro

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.