Section 18.2. Objective 2: Tune the User Environment and System Environment Variables


18.2. Objective 2: Tune the User Environment and System Environment Variables

When you create a new user account on your Linux system, some basic setup information is necessary for the user to initially become productive. When the user logs into the system, she will need:

  • A minimal set of environment variables, including a PATH that is meaningful for your system

  • Basic configuration files in her home directory

The amount of default information you provide can range from minimal to extremely detailed. In general, you'll want to provide the setup information that will allow the user to begin working without extensive personal customization.

18.2.1. Systemwide Startup Scripts

When the bash shell starts, it looks for a number of configuration script files, including /etc/profile. Commands in this file are executed at login time and contain global startup information and settings for all users. Example 18-1 contains an example profile.

Example 18-1. Sample /etc/profile

 PATH="$PATH:/usr/X11R6/bin" PS1="[\u@\h \W]\\$ " ulimit -c 1000000 if [ 'id -gn' = 'id -un' -a 'id -u' -gt 14 ]; then         umask 002 else         umask 022 fi USER='id -un' LOGNAME=$USER MAIL="/var/spool/mail/$USER" HOSTNAME='/bin/hostname' HISTSIZE=1000 HISTFILESIZE=1000 INPUTRC=/etc/inputrc PATH="$PATH:/usr/local/bin" export PATH PS1 HOSTNAME HISTSIZE HISTFILESIZE USER LOGNAME MAIL INPUTRC 

The syntax for bash programming is in Chapter 17. However, you can see that this file does basic shell setup for the user, including the assignment of a number of environment variables. As an example of a common local customization, note the line containing PATH= adds an additional directory to those already listed in the PATH environment variable. In this case, the system administrator expects that most users will need to run programs stored in /usr/X11R6/bin. Making this modification once in /etc/profile eliminates the need for individuals to make it in their personal bash profiles.

Functions and aliases are not inherited by new shells, and commands in /etc/profile are executed only at login time. For these reasons, the definition of functions and aliases typically is not done in /etc/profile, but instead either in each individual user's .bashrc, or a central location such as /etc/bashrc that is called by the user's .bashrc. Commands in the .bashrc file are executed each time a new shell starts; their effects will apply to all new shells.

On the Exam

Remember that /etc/profile is executed only when a new login shell is started, while .bashrc in the user's home directory is called for each new shell invocation.


18.2.2. Setting the Home Directory for New Accounts

When creating a new account, usually you'll want to create a default home directory for the user of the account. On Linux systems, the home directory is most likely something like /home/username, but you can define it in any way you like.

When you create a new home directory, it is a courtesy to the new user to initially populate the directory with useful files. These might include startup files for the user's shell, for his desktop, or for X Window applications. To facilitate the automated population of new user directories, an example home directory is created in a skeleton directory /etc/skel. This directory should contain all of the files and subdirectories that all new users will need. Example 18-2 shows the contents of an example /etc/skel directory.

Example 18-2. Sample skeleton (/etc/skel) directory

 -rw-r--r--  1 root     root           24 Jun 24       .bash_logout -rw-r--r--  1 root     root          191 Apr  9 07:59 .bash_profile -rw-r--r--  1 root     root          124 Apr  9 07:59 .bashrc -rw-r--r--  1 root     root          854 Aug 28  2002 .emacs drwxr-xr-x  3 root     root         4096 Aug 12  2002 .kde 

This example /etc/skel directory contains:

  • Three configuration files for the shell (.bash_logout, .bash_profile, and .bashrc)

  • A configuration file for the Emacs editor (.emacs)

  • A directory for KDE (.kde)

The specifics of this example are not important, but illustrate that a number of default files can be included in a new user's account setup. Additions could include default files for other desktop environments such as GNOME as well as startup files for other shells.

When a new account is created with a home directory, the entire contents of /etc/skel are copied recursively (that is, including subdirectories) to the new home directory location. The home directory and its entire contents are then set to the new account's UID and GID, making the new user owner of her initial files. She is then free to modify these files and directories as necessary.

As the system administrator, you may add, modify, and delete files in /etc/skel as needed for your environment.



LPI Linux Certification in a Nutshell
LPI Linux Certification in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596005288
EAN: 2147483647
Year: 2004
Pages: 257

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net