bash loging, startup scripts and shell initialization files

Date 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:
  1. /etc/passwd
  2. /etc/shadow
  3. /etc/group
  4. /etc/profile will run.
  5. then all the files (that end with sh) in the /etc/profile.d directory
  6. 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: 1. /etc/passwd /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): Name:Password:UserID:PrincipleGroup:Gecos:HomeDirectory:Shell 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 2. /etc/shadow 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 http://db.assam-glug.org/documentations/Linux-admin-made-easy/shadow-file-formats.html 3. /etc/group /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: group_name:passwd:GID:user1,user2,user3....userN as you see, you have to sperate each user with comma. for more info see: manpages: man group 4. /etc/profile /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. 5. /etc/profile.d/*.sh /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. * ~/.bashrc 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: http://www.faqs.org/docs/linux_admin/x2331.html to understand them better (/etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile, ~/.bashrc, /etc/bashrc and and ~/.bash_logout) this sites may give help: http://www.faqs.org/docs/abs/HTML/files.html http://www.faqs.org/docs/securing/chap6sec64.html http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_01.html http://www.linux-migration.org/ch02s03.html http://www.gnu.org/software/bash/manual/bash.html http://www.comptechdoc.org/os/linux/usersguide/linux_ugenvironment.html http://www.linuxfromscratch.org/blfs/view/6.1/postlfs/profile.html
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Reddit
  • Webnews
  • MisterWong
  • Y!GG

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>