Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
4.  Managing User Accounts and Groups (Overview) Where User Account and Group Information Is Stored Fields in the group File Default group file  Previous   Contents   Next 
   
 

Customizing a User's Work Environment

Part of setting up a user's home directory is providing user initialization files for the user's login shell. A user initialization file is a shell script that sets up a work environment for a user after the user logs in to a system. Basically, you can perform any task in a user initialization file that you can do in a shell script, but its primary job is to define the characteristics of a user's work environment, such as a user's search path, environment variables, and windowing environment. Each login shell has its own user initialization file (or files), which are listed in the following table.

Table 4-16 User Initialization Files for Bourne, C, and Korn Shells

Shell

User Initialization File

Purpose

Bourne

$HOME/.profile

Defines user's environment at login

 

C

$HOME/.cshrc

Defines user's environment for all C shells; invoked after login shell

 

$HOME/.login

Defines user's environment at login

 

Korn

$HOME/.profile

Defines user's environment at login

 

$HOME/$ENV

Defines user's environment at login in the file; specified by the Korn shell's ENV environment variable

The Solaris environment provides default user initialization files for each shell in the /etc/skel directory on each system, as shown in the following table.

Table 4-17 Default User Initialization Files

Shell

Default File

C

/etc/skel/local.login

 

/etc/skel/local.cshrc

Bourne or Korn

/etc/skel/local.profile

You can use these files as a starting point and modify them to create a standard set of files that provide the work environment common to all users, or you can modify them to provide the working environment for different types of users. For step-by-step instructions on how to create sets of user initialization files for different types of users, see "How to Customize User Initialization Files".

When you use the Users Tool to create a new user account and select the create home directory option, the following files are created, depending on which login shell is selected:

Shell

Files Created

C

The /etc/skel/local.cshrc and the /etc/skel/local.login files are copied into the user's home directory and are renamed .cshrc and .login.

Bourne and Korn

The /etc/skel/local.profile file is copied into the user's home directory and renamed .profile.

If you use the useradd command to add a new user account and specify the /etc/skel directory by using the -k and -m options, all three /etc/skel/local* and /etc/skel/.profile files are copied into the user's home directory. At this point, you'll need to rename them to whatever is appropriate for the user's login shell.

Using Site Initialization Files

The user initialization files can be customized by both the administrator and the user. This important feature can be accomplished with centrally located and globally distributed user initialization files, called site initialization files. Site initialization files enable you to continually introduce new functionality to the user's work environment, while enabling the user to customize the user's initialization file.

When you reference a site initialization file in a user initialization file, all updates to the site initialization file are automatically reflected when the user logs in to the system or when a user starts a new shell. Site initialization files are designed for you to distribute site-wide changes to users' work environments that you did not anticipate when you added the users.

Any customization that can be done in a user initialization file can be done in a site initialization file. These files typically reside on a server (or set of servers), and appear as the first statement in a user initialization file. Also, each site initialization file must be the same type of shell script as the user initialization file that references it.

To reference a site initialization file in a C-shell user initialization file, place a line similar to the following at the beginning of the user initialization file:

source /net/machine-name/export/site-files/site-init-file

To reference a site initialization file in a Bourne- or Korn-shell user initialization file, place a line similar to the following at the beginning of the user initialization file:

. /net/machine-name/export/site-files/site-init-file

Avoid Local System References

You should not add specific references to the local system in the user's initialization file. You want the instructions in a user initialization file to be valid regardless of the system to which the user logs in. For example:

  • To make a user's home directory available anywhere on the network, always refer to the home directory with the variable $HOME. For example, use $HOME/bin instead of /export/home/username/bin. $HOME works when the user logs in to another system and the home directories are automounted.

  • To access files on a local disk, use global path names, like /net/system-name/directory-name. Any directory referenced by /net/system-name can be mounted automatically on any system on which the user logs in, assuming the system is running AutoFS.

Shell Features

The following table lists basic shell features that each shell provides, which can help you determine what you can and can't do when creating user initialization files for each shell.

Table 4-18 Basic Features of Bourne, C, and Korn Shells

Feature

Bourne

C

Korn

Known as the standard shell in UNIX

Yes

No

No

Compatible syntax with Bourne shell

-

No

Yes

Job control

Yes

Yes

Yes

History list

No

Yes

Yes

Command-line editing

No

Yes

Yes

Aliases

No

Yes

Yes

Single-character abbreviation for login directory

No

Yes

Yes

Protection from overwriting (noclobber)

No

Yes

Yes

Setting to ignore Control-d (ignoreeof)

No

Yes

Yes

Enhanced cd

No

Yes

Yes

Initialization file separate from .profile

No

Yes

Yes

Logout file

No

Yes

No

Shell Environment

A shell maintains an environment that includes a set of variables defined by the login program, the system initialization file, and the user initialization files. In addition, some variables are defined by default. A shell can have two types of variables:

  • Environment variables - Variables that are exported to all processes spawned by the shell. Their settings can be seen with the env command. A subset of environment variables, like PATH, affects the behavior of the shell itself.

  • Shell (local) variables - Variables that affect only the current shell. In the C shell, a set of these shell variables have a special relationship to a corresponding set of environment variables. These shell variables are user, term, home, and path. The value of the environment variable counterpart is initially used to set the shell variable.

In the C shell, you use the lowercase names with the set command to set shell variables and use uppercase names with the setenv command to set environment variables. If you set a shell variable, the shell sets the corresponding environment variable and vice versa. For example, if you update the path shell variable with a new path, the shell also updates the PATH environment variable with the new path.

In the Bourne and Korn shells, you use the uppercase names with the setenv command to set both shell and environment variables. You also have to use the export command to finish setting environment variables. For all shells, you generally refer to shell and environment variables by their uppercase names.

In a user initialization file, you can customize a user's shell environment by changing the values of the predefined variables or by specifying additional variables. The following table shows how to set environment variables in a user initialization file.

Table 4-19 Setting Environment Variables in a User Initialization File

Set a User's Environment Variables for The Shell Type

Line to Add to the User Initialization File

C shell

setenv VARIABLE value

Example:

setenv MAIL /var/mail/ripley

Bourne or Korn shell

VARIABLE=value; export VARIABLE

Example:

MAIL=/var/mail/ripley;export MAIL

The following table describes environment and shell variables you might want to customize in a user initialization file. For more information about variables used by the different shells, see sh(1), ksh(1), or csh(1).

Table 4-20 Shell and Environment Variable Descriptions

Variable

Description

CDPATH (or cdpath in the C shell)

Sets a variable used by the cd command. If the target directory of the cd command is specified as a relative path name, the cd command first looks for the target directory in the current directory ("."). If the target is not found, the path names listed in the CDPATH variable are searched consecutively until the target directory is found and the directory change is completed. If the target directory is not found, the current working directory is left unmodified. For example, the CDPATH variable is set to /home/jean, and two directories exist under /home/jean, bin and rje. If you are in the /home/jean/bin directory and type cd rje, you change directories to /home/jean/rje, even though you do not specify a full path.

history

Sets history for the C shell.

HOME (or home in the C shell)

Sets the path to the user's home directory.

LANG

Sets the locale.

LOGNAME

Defines the name of the user currently logged in. The default value of LOGNAME is set automatically by the login program to the user name specified in the passwd file. You should only need to refer to (not reset) this variable.

LPDEST

Sets the user's default printer.

MAIL

Sets the path to the user's mailbox.

MANPATH

Sets the hierarchies of man pages available.

PATH (or path in the C shell)

Specifies, in order, the directories that the shell searches to find the program to run when the user types a command. If the directory is not in the search path, users must type the complete path name of a command.

The default PATH is automatically defined and set as specified in .profile (Bourne or Korn shell) or .cshrc (C shell) as part of the login process.

The order of the search path is important. When identical commands exist in different locations, the first command found with that name is used. For example, suppose that PATH is defined (in Bourne and Korn shell syntax) as PATH=/bin:/usr/bin:/usr/sbin:$HOME/bin and a file named sample resides in both /usr/bin and /home/jean/bin. If the user types the command sample without specifying its full path name, the version found in /usr/bin is used.

prompt

Defines the shell prompt for the C shell.

PS1

Defines the shell prompt for the Bourne or Korn shell.

SHELL (or shell in the C shell)

Sets the default shell used by make, vi, and other tools.

TERMINFO

Specifies the path name for an unsupported terminal that has been added to the terminfo file. Use the TERMINFO variable in /etc/profile or /etc/.login.

 

When the TERMINFO environment variable is set, the system first checks the TERMINFO path defined by the user. If it does not find a definition for a terminal in the TERMINFO directory defined by the user, it searches the default directory, /usr/share/lib/terminfo, for a definition. If it does not find a definition in either location, the terminal is identified as "dumb."

TERM (or term in the C shell)

Defines the terminal. This variable should be reset in /etc/profile or /etc/.login. When the user invokes an editor, the system looks for a file with the same name as the definition of this environment variable. The system searches the directory referenced by TERMINFO to determine the terminal characteristics.

TZ

Sets the time zone, which is used to display dates, for example, in the ls -l command. If TZ is not set in the user's environment, the system setting is used. Otherwise, Greenwich Mean Time is used.

The PATH Variable

When the user executes a command by using the full path, the shell uses that path to find the command. However, when users specify only a command name, the shell searches the directories for the command in the order specified by the PATH variable. If the command is found in one of the directories, the shell executes it.

A default path is set by the system, but most users modify it to add other command directories. Many user problems related to setting up the environment and accessing the right version of a command or a tool can be traced to incorrectly defined paths.

 
 
 
  Previous   Contents   Next