- Account Administration
- Administrative System Files
- User Account Initialization Files
- Summary
- Exam Prep Practice Questions
- Need to Know More?
User Account Initialization Files
Several initialization (or startup) files are associated with each user account home directory. These files are used to specify commands to be executed when the associated event occurs. Depending on the login shell being used (Bourne Shell, C Shell, or Korn Shell), there might be a login initialization file, a shell startup file, or a logout file. Table 3.8 lists the various initialization files.
Table 3.8 Initialization Files
File |
Bourne (sh) |
C (csh) |
Korn (ksh) |
Login initialization file |
.profile |
.login |
.profile |
Shell startup initialization file |
N/A |
.cshrc |
user-defined |
Logout file |
N/A |
.logout |
N/A |
Commands in the login initialization file are executed when the user logs in. All three common shells provide a login initialization file. Commands in the shell startup file are executed whenever the logged-in user starts a shell. Both csh and ksh provide this capability. The ENV parameter is used to define the name of the ksh shell startup initialization file. Only csh provides a file for automatic execution of commands when a user logs out.
CAUTION
It is important to know the names of the initialization files and their uses, not only for the Bourne shell, but also the C and Korn shells.
The System Profile
For user accounts that use sh (Bourne shell) or ksh as a login shell, commands in the system profile are executed before the user's login initialization file. This file is named /etc/profile and, when executed, sets a default terminal type (TERM) and then calls umask(1) to set the default file permission mask to 022. If the user's home directory does not include a file by the name of .hushlogin, the user's storage quota is displayed using quot(1M), the message of the day (if any) is displayed, and a notification message is displayed if new email has arrived for the user.
The following listing shows the default contents of /etc/profile for a Solaris 9 system:
#ident "@(#)profile 1.19 01/03/13 SMI" /* SVr4.0 1.3 */ # The profile that all logins get before using their own .profile. trap "" 2 3 export LOGNAME PATH if [ "$TERM" = "" ] then if /bin/i386 then TERM=sun-color else TERM=sun fi export TERM fi # Login and -su shells get /etc/profile services. # -rsh is given its environment in its .profile. case "$0" in -sh | -ksh | -jsh | -bash) if [ ! -f .hushlogin ] then /usr/sbin/quota # Allow the user to break the Message-Of-The-Day only. trap "trap '' 2" 2 /bin/cat -s /etc/motd trap "" 2 /bin/mail -E case $? in 0) echo "You have new mail." ;; 2) echo "You have mail." ;; esac fi esac umask 022 trap 2 3
Initialization File Templates
When a user account is created and a home directory specified, part of setting up the user account is to copy the appropriate default initialization files to the user's home directory. These initial files or templates are stored in the /etc/skel directory.
For user accounts that use sh or ksh as the login shell, the /etc/skel/local.profile file is copied to the .profile file in the user's home directory. The following listing shows the default contents of the /etc/skel/local.profile file:
# Copyright (c) 2001 by Sun Microsystems, Inc. # All rights reserved. # # ident "@(#)local.profile 1.10 01/06/23 SMI" stty istrip PATH=/usr/bin:/usr/ucb:/etc:. export PATH #
For user accounts that use csh as the login shell, the /etc/skel/local.login file is copied to the .login file in the user's home directory. The following listing shows the default contents of the /etc/skel/local.login file:
# Copyright (c) 2001 by Sun Microsystems, Inc. # All rights reserved. # # ident "@(#)local.login 1.7 01/06/23 SMI" stty -istrip # setenv TERM ´tset -Q -´
In addition, for user accounts that use csh as the login shell, the /etc/skel/local.cshrc file is copied to the .cshrc file in the user's home directory. The following listing shows the default contents of the /etc/skel/local.cshrc file:
#ident "@(#)local.cshrc 1.2 00/05/01 SMI" umask 022 set path=(/bin /usr/bin /usr/ucb /etc .) if ( $?prompt ) then set history=32 endif
Also in the /etc/skel directory is a simple .profile that can also be used as a default:
# This is the default standard profile provided to a user. # They are expected to edit it to meet their own needs. MAIL=/usr/mail/${LOGNAME:?}
When an account is created using the admintool command, the appropriate /etc/skel file is copied to the home directory of the user account based on the selected login shell (that is, .profile for Bourne and Korn shells, .cshrc for C shell, and so on). However when the useradd command is used, all the /etc/skel files (.profile, local.cshrc, local.login, and local.profile) are copied to the home directory regardless of the selected shell. In this case, the appropriate file(s) (based on type of shell) must be manually configured.
Customizing the User Environment
The initialization file templates can be modified to provide a custom environment for new user accounts. In addition, the system profile (/etc/profile) can be modified to customize the environment for all users during login initialization.
CAUTION
Keep in mind that the system profile, /etc/profile, is executed before the user's profile. This provides the ability to control and restrict the user environment before the user has an opportunity to make any modifications.
To customize individual user accounts, the initialization files in the user's home directories can be modified. For the most part, this will consist of adding commands to be automatically executed or defining shell parameters.
Defining Shell Variables in .profile
Variables defined and exported in the .profile become part of the user's environment. These variables are available to programs and shells executed by the user.
A common shell variable defined in the .profile is LPDEST, which is used to specify a default printer. To define HPLaser as the default printer, include the following in the .profile for a user account:
LPDEST=HPLaser export LPDEST
An alternative way is to specify both commands on the same line and separate the commands with a semicolon, as shown in the following:
LPDEST=HPLaser; export LPDEST
A similar syntax can be used for a user account that uses the Korn shell as a login shell. ksh also supports the following variation:
export LPDEST=HPLaser
Although defining variables for csh user accounts is not a certification requirement, the syntax for two csh methods of defining variables is shown in the following listing:
set LPDEST=HPlaser setenv LPDEST HPlaser
NOTE
Changes made to the user's login initialization file do not take effect until the user logs in again, or until the .profile is executed by preceding it with a dot separated by a space. This executes the .profile and makes it part of the current environment.
Sourcing .profile
For user accounts that use the Solaris Common Desktop Environment (CDE), the /usr/dt/bin/Xsession command that starts the desktop can be configured to read and process the .login (csh) or .profile (sh and ksh) login initialization file in the user's home directory as part of the startup process.
The first user-specific file that Xsession calls is the .dtprofile file, located in the user's home directory. The last line of the default .dtprofile file is as follows:
DTSOURCEPROFILE=true
This will cause the .login or .profile file to be executed (or sourced) automatically. To change this default behavior and prevent the login initialization file from being sourced, change true to false.