|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
|
| News | Redbooks | IBM Links | Recommended Links | Recommended eBooks and Papers | FAQs | Hardening | Security |
After bootup the AIX displays a login prompt on what looks like a character-based terminal, but which in reality is part of what is known as a high-function terminal (hft). An hft is not just a display; it also includes the keyboard, the mouse, dials, and keypad.
Logging in to the AIX, therefore, follows the typical UNIX login process: The getty process provides the login screen. If a user enters an id at this getty login prompt, getty starts the login process to validate the user. Like linux and Solaris AIX's login program checks not only /etc/passwd, which contains user names, but also a shadow password file, /etc/security/passwd, which contains the encrypted passwords of each of the users. login then starts a login shell as defined in /etc/passwd for the user, which by default is the KornShell (ksh). [ksh then reads the user's .profile. It is here in .profile that X Window can be started by calling the xinit command either directly or via the startx script.
The xinit command starts the X server and then reads the $HOME/.xinitrc file to determine which X programs to start. The three most likely applications to run from .xinitrc are
When a user exits his or her X Window session and logs out, control of the terminal returns to the init process, which spawns a new getty process, which in turn displays the Console Login on the display.
The following summarizes the AIX login process:
Other AIX login environments include xdm (X Display Manager), which provides an X Window login interface, and a ASCII-only display session. But the process described above is the most common.
If you are in an X Window session, stopping it by choosing End Session on the Root Menu will usually log you out. However, if your system displays an ASCII screen with a command line prompt (usually a "$" prompt) after you stop X, then you have to take the additional step of closing the shell by typing either the exit command or the logout commands.
The reason you might see a command line prompt after stopping the X server is because of the AIX concept of virtual terminals. The hft device is capable of supporting multiple screens on a single terminal. To create a virtual terminal you simply type the open command followed by the name of the program you want to run in the new virtual terminal. If you type open ksh, or if your .profile contains such a command, then you get a second screen running a KornShell. To access other screens, you simply type the CTRL+ALT/ACTION key sequence, and the terminal displays each screen one at a time.
If the X server is started by the open command, for example open xinit, it appears in its own screen. Thus ending the X Window session simply stops the X server in that particular screen and leaves other virtual terminals still running. To log out requires closing all virtual terminals, so whatever programs are running in them, be they shells or additional X servers, they must be closed in order to logout
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 off the system.
The shell uses two types of profile files when you log in to the operating system. It evaluates the commands contained in the files and then executes the commands to set up your system environment. The files have similar functions except that the /etc/profile file controls profile variables for all users on a system whereas the .profile file allows you to customize your own environment.
The shell first evaluates the commands contained in the /etc/profile file and then runs the commands to set up your system environment in the /etc/environment file. After these files are run, the system then checks to see if you have a .profile file in your home directory. If the .profile file exists, it runs this file. The .profile file will specify if there also exists an environment file. If an environment file exists, (usually called .env), the system then runs this file and sets up your environment variables.
The /etc/profile, /etc/environment, and the .profile files are run once at login time. The .env file, on the other hand, is run every time you open a new shell or a window.
This section discusses the following initialization files:
/etc/profile File
The first file that the operating system uses at login time is the /etc/profile file. This file controls systemwide 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 profile file for all users on the system. Only the system administrator can change this file.
The following example is typical of an /etc/profile file:
#Set file creation mask unmask 022 #Tell me when new mail arrives MAIL=/usr/mail/$LOGNAME #Add my /bin directory to the shell search sequence PATH=/usr/bin:/usr/sbin:/etc:: #Set terminal type TERM=lft #Make some environment variables global export MAIL PATH TERMSee .profile File Format in the AIX Version 4.3 Files Reference for detailed information about the /etc/profile file.
/etc/environment File
The second file that the operating system uses at login time is the /etc/environment file. The /etc/environment file contains variables specifying the basic environment for all processes. When a new process begins, the exec subroutine makes an array of strings available that have the form Name=Value. This array of strings is called the environment. Each name defined by one of the strings is called an environment variable or shell variable. The exec subroutine allows the entire environment to be set at one time.
When you log in, the system sets environment variables from the environment file before reading your login profile, .profile. The following variables make up the basic environment:
HOME The full path name of the user's login or HOME directory. The login program sets this to the name specified in the /etc/passwd file. LANG The locale name currently in effect. The LANG variable is initially set in the /etc/profile file at installation time. NLSPATH The full path name for message catalogs. LOCPATH The full path name of the location of National Language Support tables. PATH The sequence of directories that commands, such as sh, time, nice and nohup, search when looking for a command whose path name is incomplete. TZ The time zone information. The TZ environment variable is initially set by the /etc/profile file, the system login profile. See .environment File in the AIX Version 4.3 Files Reference for detailed information about the /etc/environment file.
.profile File
The third file that the operating system uses at login time is the .profile file. The .profile file is present in your home ($HOME) directory and enables you to customize your individual working environment. Because the .profile file is hidden, use the li -a command to list it.
After the login program adds the LOGNAME (login name) and HOME (login directory) variables to the environment, the commands in the $HOME/.profile file are executed if the file is present. The .profile file contains your individual profile that overrides the variables set in the /etc/profile file. The .profile file is often used to set exported environment variables and terminal modes. You can tailor your environment as desired by modifying the .profile file. Use the .profile file to control the following defaults:
- Shells to open
- Prompt appearance
- Keyboard sound.
The following example shows a typical .profile file:
PATH=/usr/bin:/etc:/home/bin1:/usr/lpp/tps4.0/user:: epath=/home/gsc/e3: export PATH epath cshThis example has defined two path variables (PATH and epath), exported them, and opened a C shell (csh).
You can also use the .profile file (or if it is not present, the /etc/profile file) to determine login shell variables. You can also customize other shell environments. For example, use the .cshrc file and .kshrc file to tailor a C shell and a Korn shell, respectively, when each type of shell is started.
.env File
A fourth file that the operating system uses at login time is the .env file, if your .profile has the following line: export ENV=$HOME/.env
The .env file enables you to customize your individual working environment variables. Because the .env file is hidden, use the li -a command to list it. The .env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can tailor your environment variables as desired by modifying your .env file. The following example shows a typical .env file:
export myid=`id | sed -n -e 's/).*$//' -e 's/^.*(//p'` export bold=`tput smso` export norm=`tput rmso` #set prompt: login & system name (reverse video) & path (normal) if [ $myid = root ] then typeset -x PSCH='${bold}#:${norm}\${PWD}> ' PS1="${bold}#:${norm}\${PWD}> " else typeset -x PSCH='>' PS1="${bold}$LOGNAME@$UNAME:${norm}\${PWD}> " PS2=">" PS3="#?" fi export PS1 PS2 PS3 #setup my command aliases alias ls="/bin/ls -CF" \ d="/bin/ls -Fal | pg" \ rm="/bin/rm -i" \ up="cd .."Note: When modifying the .env file, ensure that newly created environment variables do not conflict with standard variables such as MAIL, PS1, PS2, and IFS.
The following is a sample of a .kshrc script on one specific system. The contents of your .kshrc file can be significantly different.
# @(#).kshrc 1.0# Base Korn Shell environment# Approach:# shell initializations go in ~/.kshrc # user initializations go in ~/.profile # host / all_user initializations go in /etc/profile # hard / software initializations go in /etc/environment# DEBUG=y # uncomment to report[ "$DEBUG" ] && echo "Entering .kshrc"set -o allexport# options for all shells --------------------------------# LIBPATH must be here because ksh is setuid, and LIBPATH is # cleared when setuid programs are started, due to security hole.LIBPATH=.:/local/lib:/lib:/usr/lib# options for interactive shells follow-------------------------TTY=$(tty|cut -f3-4 -d/) HISTFILE=$HOME/.sh_hist$(echo ${TTY} | tr -d '/') PWD=$(pwd) PS1='${LOGNAME}@${HOSTNAME} on ${TTY}[${PWD}] '# aliases[ "$DEBUG" ] && echo "Setting aliases" alias pg="pg -n -p':Page %d: '" alias more="pg -n -p':Page %d: '" alias cls="tput clear" alias sane="stty sane" alias rsz='eval $(resize)'# mail checkif [ -s "$MAIL" ] # This is at Shell startup. In then echo"$MAILMSG" # normal operation, the Shell checks fi # periodically.# aixterm window title
[[ "$TERM" = "aixterm" ]] && echo "\033]0;$USER@${HOSTNAME%t1}\007"# functions[ "$DEBUG" ] && echo "Setting functions"function pid { ps -e | grep $@; }function term { if [ $# -eq 1 ] then echo $TERM TERM=$1 export TERM fi echo $TERM }function back {cd $OLDPWD echo $CWD $OLDPWD }[ "$DEBUG" ] && echo "Exiting .kshrc"set +o allexport
HOST=`hostname` export PS1='^[[01;32m${USER}@^[[1;34m${HOST%%.*} ^[[01;36m${PWD##*/} $^[[0m 'HOST=`hostname`
export PS1='${USER}@${HOST} ${PWD} $ 'AIX's ksh
The ksh that ships with IBM's AIX lacks tab completion and history with arrow keys. As googling for the solutions indicates that a great many people have the same question, here are the quick and dirty answers.One can choose to set -o emacs or set -o vi. Most bash users are familiar with what this means. The default bash (and many other shells) option is emacs mode, where simple command line editing is possible using emacs style keystrokes. Using vi mode uses vi style keystrokes. However, even many vi users use emacs mode for the command line.
With AIX, one has to set this, either on the command line or in your .profile. If you choose the emacs mode, command and filename completion is done with esc esc (in other words, hitting the escape key twice.) History is done with ctl+p and ctl+n, as in previous and next. Googling gives some keybindings you can add to use the arrow keys instead, but I never bothered.
If you are in vi mode then esc \ gives filename and command completion and history is done with esc k for the previous command. If you want to keep going back, after the first time, you can just hit k.
Anyway, these were the little things I had to look up to get my ksh working as I wanted it to work. Hopefully, some may find it of use.
The Korn Shell:
The Korn shell does support colors. To color the prompt you will want to place this symbol in your prompt.$'\E[Xm'. Replace X with the number of the color you want. Example:
PS1=$'\E[31m'`logname`@`hostname -s`:$'\E[0m>' #Custom prompt settings.
PS1 = "red text whoami hostname normal display>"
So basically you have told the computer all text from here to be red. After that you have told the computer to place the hostname and whoami in the prompt. Now return the display to a normal setting. This is important because forgetting to tell it to go back to normal means everything will be red, or worse whatever your last color command is. The point being when you are done make sure you tell it to return to normal.
Okay more than one color:
PS1=$'\E[31m'`logname`@$'\E[1;33m'`hostname -s`:$'\E[0m>' #Custom prompt settings
PS1 = "red text whoami yellow text hostname normal display>
Okay background color:
PS1=$'\E[46;31m'`logname`@$'\E[1;33m'`hostname -s`:$'\E[0m>' #Custom prompt settings
PS1 ="Cyan background red text whoami yellow text hostname normal display>" You can have multiple colors in the brackets. Separate them with a semicolon. Also don't ask for two colors to cover the same text. Your computer will get mad at you.
Certain colors need a semicolon in order to appear. Yellow as the above example shows is 1;33 do not use just 33 or it will come out brown. If you have a 0;31 you don't need to place the 0.
These are just some of things you can do. Don't be afraid to experiment. Post your Korn shell prompt here.
Prompt
export myid=`id | sed -n -e 's/).*$//' -e 's/^.*(//p'`
export bold=`tput smso`
export norm=`tput rmso`
#set prompt: login & system name (reverse video) & path (normal)
if [ $myid = root ]
then typeset -x PSCH='${bold}#:${norm}\${PWD}> '
PS1="${bold}#:${norm}\${PWD}> "
else typeset -x PSCH='>'
PS1="${bold}$LOGNAME@$UNAME:${norm}\${PWD}> "
PS2=">"
PS3="#?"
fi
export PS1 PS2 PS3
# @(#).kshrc 1.0# Base Korn Shell environment# Approach:# shell initializations go in ~/.kshrc # user initializations go in ~/.profile # host / all_user initializations go in /etc/profile # hard / software initializations go in /etc/environment# DEBUG=y # uncomment to report[ "$DEBUG" ] && echo "Entering .kshrc"set -o allexport# options for all shells --------------------------------# LIBPATH must be here because ksh is setuid, and LIBPATH is # cleared when setuid programs are started, due to security hole.LIBPATH=.:/local/lib:/lib:/usr/lib# options for interactive shells follow-------------------------TTY=$(tty|cut -f3-4 -d/) HISTFILE=$HOME/.sh_hist$(echo ${TTY} | tr -d '/') PWD=$(pwd) PS1='${LOGNAME}@${HOSTNAME} on ${TTY}[${PWD}] '# aliases[ "$DEBUG" ] && echo "Setting aliases" alias pg="pg -n -p':Page %d: '" alias more="pg -n -p':Page %d: '" alias cls="tput clear" alias sane="stty sane" alias rsz='eval $(resize)'# mail checkif [ -s "$MAIL" ] # This is at Shell startup. In then echo"$MAILMSG" # normal operation, the Shell checks fi # periodically.# aixterm window title
[[ "$TERM" = "aixterm" ]] && echo "\033]0;$USER@${HOSTNAME%t1}\007"# functions[ "$DEBUG" ] && echo "Setting functions"function pid { ps -e | grep $@; }function term { if [ $# -eq 1 ] then echo $TERM TERM=$1 export TERM fi echo $TERM }[ "$DEBUG" ] && echo "Exiting .kshrc"set +o allexport
Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.
Last modified: June 05, 2008