What Happens When a User Logs In?

Well environment variables used to customize a user’s login environment can be defined from the command line, they are more commonly defined by several scripts that execute during the login process. Typically, three scripts execute during the login process to initialize the user’s environment.

The first is a system-wide script maintained by the system administrator to define general environment variables required by all users.

The second is a local login script maintained by each user. Local login scripts can override or modify the system defaults on a user-by-user basis.

The optional additional local login script can define additional environment variables or set additional shell features. In the POSIX shell, this additional script is often used to define shell aliases.

The login script names vary from shell to shell. A detailed discussion of the login scripts used by the POSIX, Korn, and C shells follows:

Shell Environment Initialization Sequence

  • The shell runs the appropriate system login script, which initializes the user’s environment. The system login scripts define a default environment, and can be customized by the system administrator.
    The System Login Script is…
If the Shell is… The System Login Script is…
Bourne (/usr/old/bin/sh) /etc/profile
Korn (/usr/bin/ksh) /etc/profile
POSIX (/usr/bin/sh) /etc/profile
Restricted (/usr/bin/rsh , /usr/bin/rksh) /etc/profile
C (/usr/bin/csh) /etc/csh.login



As shipped, these scripts define and export for shell use the environment variables PATH, TZ, and TERM. Inside these scripts, the files /etc/PATH, /etc/MANPATH, /etc/TIMEZONE, /etc/SHLIB_PATH are sourced. Since the system login scripts are run for all users at login, the system administrator can modify these files to set global defaults for all users.  This is useful for ensuring that each user runs essential commands at login.

  • Displays the contents of the /etc/copyright and /etc/motd file.
  • Notifies the user of unread news with the prompt:

news: news_filename

  • The shell runs the user’s local login script (if it exists) in the user’s home (login) directory:
If the Shell is … The Local Login Script is …
Bourne (/usr/old/bin/sh) .profile
Korn (/usr/bin/ksh ) .profile
Posix (/usr/bin/sh .profile
Restricted (/usr/bin/rsh .profile
C (/usr/bin/csh) .login


NOTE: Typically, the system administrator initially creates a local login script for each user. If SAM or useradd is used to add a user, it copies the default local login script (the /etc/skel/.profile) to the user’s home directory. Users can further customize their environments by modifying these files to suit their needs.
In addition to the above scripts, the POSIX, Korn and C shells may (and usually do) have additional local login scripts:

— POSIX and Korn shell – if the ENV variable is defined, the shell runs the file defined by ENV (typically, .shrc whenever a new shell is started. Many programs (for example, vi and mailx) allow users to start a shell from within the program; this is called a shell escape. The ENV file is re-run for a shell escape, whereas .profile is run only at login. The ENV file (either .kshrc or .shrc) will be executed after .profile executes upon login.
— C shell – Runs the .cshrc file whenever a new C shell is started. This is similar to how the Korn shell ENV file works. The .login file is run only at login, whereas .cshrc is rerun for every new C shell. The .cshrc file will be executed before the .login upon login.

  • Once all initialization is complete, the shell displays a prompt and waits for input from the user.

Leave a Comment

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top