Go to main content

Managing User Accounts and User Environments in Oracle® Solaris 11.3

Exit Print View

Updated: March 2017
 
 

About the User Work Environment

Part of setting up the home directory for user is providing user initialization files for the login shell of the user. 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. However, a user initialization file's primary job is to define the characteristics of user 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. Note that the default user initialization file for both the bash and ksh93 shells is /etc/skel/local.profile.

Table 7  Bash and ksh93 User Initialization Files
Shell
User Initialization File
Purpose
bash
$HOME/.bash_profile
$HOME/.bash_login
$HOME/.profile
Defines the user's environment at login
ksh93
/etc/profile
$HOME/.profile
Defines the user's environment at login
(Korn)
$ENV
Defines the user's environment at login within the file and is specified by the Korn shell's ENV environment variable

You can use these files as a starting point and then modify them to create a standard set of files that provide the work environment common to all users. You can also modify these files 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.

Using Site Initialization Files

The user initialization files can be customized by both the administrator and the user. This important task can be accomplished with centrally located and globally distributed user initialization files that are 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 enable you to distribute site-wide changes to users' work environments that you did not anticipate when you added the users.

You can customize a site initialization file the same way that you customize a user 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 bash or ksh93 user initialization file, place a line at the beginning of the user initialization file similar to the following line:

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

Avoiding Local System References

Do not add specific references to the local system in the user initialization file. The instructions in a user initialization file should be valid regardless of which system the user logs into.

    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. The $HOME variable works when the user logs in to another system, and the home directories are auto-mounted.

  • To access files on a local disk, use global path names, such as /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 shell features and behavior are supported in the Oracle Solaris OS:

  • The user account that is created when you install the Oracle Solaris release is assigned the GNU Bourne-Again Shell (bash) by default.

  • The standard system shell (bin/sh) is now the Korn Shell 93 (ksh93).

  • The default interactive shell is the Bourne-again (bash) shell (/usr/bin/bash).

  • Both the bash and ksh93 shells feature command-line editing, which means you can edit commands before executing them.

  • You can display default shell and path information in a few different ways. They are as follows:

    • Use the echo $SHELL and which commands

      $ grep root /etc/passwd
      root:x:0:0:Super-User:/root:/usr/bin/bash 
      
      $ echo $SHELL
      /usr/bin/bash
      
      $ which ksh93
      /usr/bin/ksh93
    • Use the pargs command

      ~$ pargs -l $$
      /usr/bin/i86/ksh93
  • The ksh93 shell also has a built-in variable called .sh.version, which can be displayed as follows:

    ~$ echo ${.sh.version}
    Version jM 93u 2011-02-08
  • To change to a different shell, type the path of the shell that you want to use.

  • To exit a shell, type exit.

The following table describes the shell options that are supported in Oracle Solaris.

Table 8  Basic Shell Features in the Oracle Solaris Release
Shell
Path
Comments
Bourne-Again Shell (bash)
/usr/bin/bash
Default shell for users that are created by an installer, as well as the root role
The default (interactive) shell for users that are created with the useradd command as well as the root role is /usr/bin/bash. The default path is /usr/bin:/usr/sbin.
Korn Shell
/usr/bin/ksh
ksh93 is the default shell in the Oracle Solaris OS.
C Shell and enhanced C Shell
/usr/bin/csh and /usr/bin/tcsh
C Shell and enhanced C Shell
POSIX-compliant Shell
/usr/xpg4/bin/sh
POSIX-compliant shell
Z Shell
/usr/bin/zsh
Z Shell

Note -  The Z Shell (zsh) and the enhanced C Shell (tsch) are not installed on your system by default. To use either of these shells, you must first install the required software packages.

The following table shows the default UNIX® system prompt and superuser prompt for shells that are included in the Oracle Solaris OS. Note that the default system prompt that is displayed in command examples varies, depending on the Oracle Solaris release.

Table 9  Shell Prompts
Shell
Prompt
Bash shell, Korn shell, and Bourne shell
$
Bash shell, Korn shell, and Bourne shell for superuser
#
C shell
machine_name%
C shell for superuser
machine_name#

Bash and ksh93 Shell History

Both the bash and ksh93 shells record a history of all of the commands that you run. This history is kept on a per-user basis, which means the history is persistent between login sessions, as well as representative of all your login sessions.

For example, if you are in a bash shell, you can display the complete history of the commands that you have run as follows:

$ history
1 ls
2 ls -a
3 pwd
4 whoami
.
.
.

To display a number of previous commands, include an integer in the command.

$ history 2
12 date
13 history

For more information, see the history(1) man page.

Bash and Korn Shell Environment Variables

The bash and ksh93 shells store special variable information that is known to the shell as an environment variable. To view a complete list of the current environment variables for the bash shell, use the declare command.

$ declare
BASH=/usr/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINEND=()
BASH_SOuRCE=()
BASH_VERSINFO=([0]=''3'' [1]=''2'' [2]=''25'' [3]=''1''
[4]=''release'' [5]''
.
.
.

For the ksh93 shell, use the set command, which is the equivalent of the declare command in bash shell.

$ set
  COLUMNS=80
  ENV='$HOME/.kshrc'
  FCEDIT=/bin/ed
  HISTCMD=3
  HZ=''
  IFS=$' \t\n'
  KSH_VERSION=.sh.version
  LANG=C
  LINENO=1
  .
  .
  .

To print environment variables for either shell, use the echo or printf command. For example:

$ echo $SHELL
/usr/bin/bash
$ printf "$PATH\n"
/usr/bin:/usr/sbin

Note -  Environment variables do not persist between sessions. To set up persistent environment variable values, set the values in the .bashrc file.

A shell can have two types of variables:

Environment variables

Specifies variables that are exported to all processes that are spawned by the shell. The export command is used to export a variable. For example:

export VARIABLE=value

These settings can be displayed by using the env command. A subset of environment variables, such as PATH, affects the behavior of the shell itself.

Shell (local) variables

Specifies variables that affect only the current shell.

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 provides more details about the shell and environment variables that are available in the Oracle Solaris OS.

Table 10  Shell and Environment Variable Descriptions
Variable
Description
CDPATH
Sets a variable that is used by the cd command. If the target directory of the cd command is specified as a relative path name, the cd command first searches for the target directory in the current directory (.). If the target is not found, the path names that are 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, suppose the CDPATH variable is set to /home/jean, and two directories exist under /home/jean, bin and doc. If you are in the /home/jean/bin directory and type cd doc, you change directories to /home/jean/doc, even though you do not specify a full path.
HOME
Sets the path to the user's home directory.
LANG
Sets the locale.
LOGNAME
Defines the name of the user that is currently logged in. The default value of LOGNAME is automatically set by the login program to the user name that is specified in the passwd file. You should only use the variable for a reference, and not reset it.
MAIL
Sets the path to the user's mailbox.
MANPATH
Sets the hierarchies of man pages that are available.

Note -  Starting with Oracle Solaris 11, the MANPATH environment variable is no longer required. The man command determines the appropriate MANPATH based on the PATH environment variable setting.

PATH
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.
As part of the login process, the default PATH is automatically defined and set as specified in .profile.
The order of the search path is important. When identical commands exist in different locations, the first command that is found with that name is used. For example, suppose that PATH is defined in the shell syntax as PATH=/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 that is found in /usr/bin is used.
PS1
Defines the shell prompt for the bash or ksh93 shell.
SHELL
Sets the default shell used by make, vi, and other tools.
TERMINFO
Names a directory where an alternate terminfo database is stored. Use the TERMINFO variable in either the /etc/profile or /etc/.login file. For more information, see the terminfo(4) man page.
When the TERMINFO environment variable is set, the system first checks the TERMINFO path defined by the user. If the system 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 the system does not find a definition in either location, the terminal is identified as "dumb".
TERM
Defines the terminal. This variable should be reset in either the /etc/profile or /etc/.login file. When the user invokes an editor, the system looks for a file with the same name that is defined in this environment variable. The system searches the directory referenced by TERMINFO to determine the terminal characteristics.
TZ
Sets the time zone. The time zone 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.

Customizing the Bash Shell

To customize your bash shell, add to or change the information in the .bashrc file that is located in your home directory. The initial user that is created when you install Oracle Solaris has a .bashrc file that sets the PATH, MANPATH, and command prompt. For more information, see the bash(1) man page.

MANPATH Environment Variable

The MANPATH environment variable specifies where the man command looks for reference manual (man) pages. The MANPATH is set automatically based on a user's PATH value, but it generally includes /usr/share/man and usr/gnu/share/man.

Note that a user's MANPATH environment variable can be modified independent of the PATH environment variable. A one-to-one equivalent of the associated man page locations with directories in the user's $PATH is not required.

PATH Environment 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 the command.

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

Guidelines for Setting PATH Variables

    The guidelines for setting up PATH variables are as follows:

  • If you must include the current directory (.) in your path, place it last. Including the current directory in your path is a security risk because some malicious person could hide a compromised script or executable in the current directory. Consider using absolute path names instead.

  • Keep the search path as short as possible. The shell searches each directory in the path. If a command is not found, long searches can slow down system performance.

  • The search path is read from left to right, so you should put directories for commonly used commands at the beginning of the path.

  • Make sure that directories are not duplicated in the path.

  • Avoid searching large directories, if possible. Put large directories at the end of the path.

  • Put local directories before NFS mounted directories to lessen the chance of the system becoming nonresponsive when the NFS server does not respond. This strategy also reduces unnecessary network traffic.

Locale Variables

The LANG and LC environment variables specify the locale-specific conversions and conventions for the shell. These conversions and conventions include time zones, collation orders, and formats of dates, time, currency, and numbers. In addition, you can use the stty command in a user initialization file to indicate whether the terminal session will support multibyte characters.

The LANG variable sets all possible conversions and conventions for the given locale. You can set various aspects of localization separately through the LC variables LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_NUMERIC, LC_MONETARY, and LC_TIME.


Note -  By default, Oracle Solaris 11 installs UTF-8 based locales only.

The following table describes the environment variable values for the core Oracle Solaris 11 locales.

Table 11  Values for Locale Variables
Value
Locale
en_US.UTF-8
English, United States (UTF-8)
fr_FR.UTF-8
French, France (UTF-8)
de_DE.UTF-8
German, Germany (UTF-8)
it_IT.UTF-8
Italian, Italy (UTF-8)
ja_JP.UTF-8
Japanese, Japan (UTF-8)
ko_KR.UTF-8
Korean, Korea (UTF-8)
pt_BT.UTF-8
Portuguese, Brazil (UTF-8)
zh_CN.UTF-8
Simplified Chinese, China (UTF–8)
es_ES.UTF-8
Spanish, Spain (UTF-8)
zh_TW.UTF-8
Traditional Chinese, Taiwan (UTF-8)
Example 1  Setting the Locale

In an sh or ksh shell user initialization file, you would add the following:

LANG=de_DE.ISO8859-1; export LANG

Default File Permissions (umask)

When you create a file or directory, the default file permissions assigned to the file or directory are controlled by the user mask. The user mask is set by the umask command in a user initialization file. You can display the current value of the user mask by typing umask and pressing Return.

    The user mask contains the following octal values:

  • The first digit sets permissions for the user

  • The second digit sets permissions for group

  • The third digit sets permissions for other, also referred to as world

Note that if the first digit is zero, it is not displayed. For example, if the user mask is set to 022, 22 is displayed.

To determine the umask value that you want to set, subtract the value of the permissions you want from 666 (for a file) or 777 (for a directory). The remainder is the value to use with the umask command. For example, suppose you want to change the default mode for files to 644 (rw-r--r--). The difference between 666 and 644 is 022, which is the value you would use as an argument to the umask command.

The following table provides umask values . It shows the file and directory permissions that are created for each of the octal values of umask.

Table 12  Permissions for umask Values
umask Octal Value
File Permissions
Directory Permissions
0
rw-
rwx
1
rw-
rw-
2
r--
r-x
3
r--
r--
4
-w-
-wx
5
-w-
-w-
6
--x
--x
7
--- (none)
--- (none)

The following line in a user initialization file sets the default file permissions to rw-rw-rw-.

umask 000

Customizing a User Initialization File

The following example shows a sample of the .profile user initialization file. You can use this sample file as a template to customize your own user initialization files. This example uses system names and paths that you will need to modify for your particular site.

Example 2  .profile File
PATH=$PATH:$HOME/bin:/usr/local/bin:/usr/gnu/bin: User's shell search path 
MAIL=/var/mail/$LOGNAME Path to user's mail file
NNTPSERVER=server1 User's time/clock server
MANPATH=/usr/share/man:/usr/local/man User's search path for man pages
PRINTER=printer1 User's default printer
umask 022 User's default file creation permissions
export PATH MAIL NNTPSERVER MANPATH PRINTER Sets the listed environment variables