December 19, 2006
bash loging, startup scripts and shell initialization files..
ok, i will talk about bash,
When a user logs in, environment variables are set from various places.
startup scripts in order is like this:
- /etc/profile will run.
- then all the files (that end with sh) in the /etc/profile.d directory
- then bash will look for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. (i.e if ~/.bash_profile is not exists then bash will look for ~/.bash_login then ~/.profile and sources that instead). may be ~/.bash_profile source ~/.bash_login and ~/.bashrc in it.
- ~/.bashrc might point to /etc/bashrc
- at logout ~/.bash_logout may run
- bash command history are kept in ~/.bash_history
some of this scripts may not exists in your system (~/.bash_profile, ~/.bash_login, ~/.profile, ~/.bashrc, /etc/bashrc and and ~/.bash_logout),
lets we explain them:
/etc/passwd file contains basic user attributes. This is an ASCII file that contains an entry for each user. Each entry defines the basic attributes applied to a user.
An entry in the /etc/passwd file has the following form (one entry per line):
For security reasons, most Linux Distributions no longer store password in this file (store it in /etc/shadow).
A corrupt /etc/passwd file can easily render a Linux box unusable.
for more info about /etc/passwd see:
manpages: man passwd
shadow contains the encrypted password information for user’s accounts and optional the password aging information (other information such as account or password expiration values, etc).
for more info:
manpages: man shadow
/etc/group is an ASCII file which defines the groups to which users belong. There is one entry per line, and each line has the format:
as you see, you have to sperate each user with comma.
for more info see:
manpages: man group
/etc/profile file contains system wide environment stuff and startup programs, all settings that you want to apply to all your users environments should be in this file.
/etc/profile.d is a good place to put application specific settings and their environment variables.
6. ~/.bash_profile, ~/.bash_login, and ~/.profile
they can be used like /etc/profile file but for a specific user… they are user-specific bash environmental default settings, contains extra configuration options or change default settings.
bash will look for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
~/.profile is good when use another shell (like csh) that will not understand bash command and will look for this file.
this file used for user-specific aliases, export and user functions.
~/.bashrc might point to /etc/bashrc to run global things.
finaly may be you would like to know that when you create a new user, then the home directory for that user will initialised with files from the /etc/skel directory (i.e /etc/skel directory contains subdirectories and files used to populate a new user’s home directory). The system administrator can create files in /etc/skel/ directory that will provide a default environment for users.
i dont know a good site talking about that, but take a look at this one:
to understand them better (/etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile, ~/.bashrc, /etc/bashrc and and ~/.bash_logout) this sites may give help: