Shell Configuration Files
时间:2005-11-22 来源:rickyweiwei
1、/etc/bashrc
The /etc/bashrc file is used for aliases and functions, on a system-wide basis. this file sets the following bash shell parameters for each user. For example:
(1)It assigns a value of umask, which creates the default permissions for newly created files. It supports one set of permissions for root and system users (with user IDs below 100), and another for regular users.
(2)It assigns a prompt, which is what you see just before the cursor at the command prompt.
The settings here are called by the .bashrc file in each user's home directory. The settings are supplemented by the .bash_history and .bash_logout files in each user's home directory.
2、/etc/profile
The /etc/profile file is used for system-wide environments and startup files.
The first part of the file sets the PATH for searching for commands. Then it sets the PATH, USER, LOGNAME, MAIL, HOSTNAME, HISTSIZE, and INPUTRC variables, and finally it runs the scripts in the /etc/profile.d directory. You can check the current value of any of these variables with the echo $variable command.
3、/etc/profile.d/
Actually, /etc/profile.d is not a script, but a directory of scripts. As I just noted, /etc/profile runs the scripts in this directory. Here is a partial listing of the files, which apply to the default bash shell:
-rwxr-xr-x 1 root root 724 Aug 12 11:34 colorls.sh
-rwxr-xr-x 1 root root 190 Sep 8 11:32 glib2.sh
-rwxr-xr-x 1 root root 70 Sep 17 12:13 gnome-ssh-askpass.sh
-rwxr-xr-x 1 root root 210 Sep 23 15:42 krb5.sh
-rwxr-xr-x 1 root root 53 Mar 26 2003 lam.sh
-rwxr-xr-x 1 root root 2595 Sep 26 00:39 lang.sh
-rwxr-xr-x 1 root root 435 Sep 1 10:32 less.sh
-rwxr-xr-x 1 root root 70 May 1 2003 pvm.sh
-rwxr-xr-x 1 root root 181 Sep 1 11:01 vim.sh
-rwxr-xr-x 1 root root 170 Jul 17 15:09 which-2.sh
By looking at the /etc/profile script, you can see that any script in this directory that ends with an 'sh' and is set as an executable will be run when /etc/profile is executed.
3、example
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
umask 002
else
umask 022
fi
The if statement tests to see if the user ID (uid) and group ID (gid) are the same, and that the uid is greater than 99. If this is true, then the first umask is executed; otherwise, the second is executed. The second umask is for root and other key system accounts. The first is for users.
Change the first umask statement to exclude all permissions for groups and others. Use umask 077 to do the job.
We want to keep our system as secure as possible. One approach is to change the default permissions users have for new files and directories they make. We'll set all new files and directories to No Access to group or other members.
4、小结:
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置.
/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.
~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件.
~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取.
~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件.