profile
Linux user Profile Management and Environment Variable¶
User environment customization¶
The operating system provides various commands and initialization files that enable you to customize the behavior and the appearance of your user environment.
You can also customize some of the default resources of the applications you use on your system. Defaults are initiated by the program at startup. When you change the defaults, you must exit and then restart the program for the new defaults take effect.
-
System startup files When you log in, the shell defines your user environment after reading the initialization files that you have set up. The characteristics of your user environment are defined by the values given to your environment variables. You maintain this environment until you log out of the system.
-
Exporting shell variables (export shell command) A local shell variable is a variable known only to the shell that created it. If you start a new shell, the old shell's variables are unknown to it. If you want the new shells that you open to use the variables from an old shell, export the variables to make them global.
-
Changing your system prompt You can change your system prompt.
These files and procedures help the user customize the system environment.
System startup files¶
| Item | Description |
|---|---|
| /etc/profile | System file that contains commands that the system executes when you log in. |
| /etc/environment | System file that contains variables specifying the basic environment for all processes. |
| $HOME/.profile | File in your home directory that contains commands that override the system /etc/profile when you log in. For more information, see .profile file. |
| $HOME/.env | File in your home directory that overrides the system /etc/environment and contains variables specifying the basic environment for all processes. For more information, see .env file. |
Customization procedures¶
| Item | Description |
|---|---|
| PS1 | Normal system prompt |
| PS2 | More input system prompt |
| PS3 | Root system prompt |
/etc/profile file¶
The second file that the operating system uses at login time is the /etc/profile file.
The /etc/profile file controls system-wide default variables, such as:
- Export variables
- File creation mask (umask)
- Terminal types
- Mail messages to indicate when new mail has arrived
The system administrator configures the /etc/profile file for all users on the system. Only the system administrator can change this file.
The following is the system default /etc/profile file:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "${PS1-}" ]; then
if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "$(id -u)" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
Required Additional configurations¶
We are not changing the default profile but adding additional configuration scripts in /etc/profile.d
We are adding a setting so no core dumps are created and a proper default umask for root and normal users.
We are adding the default auto logout based on idle time as readonly.
We are setting the default umaks for root and users.
# By default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 027
fi