CIS 191B
Lab 6: Extra Credit: Exploring the Login Process
The purpose of this lab is to explore the various processes that take place when a user logs in to a UNIX/Linux machine. To be sure, the login process can vary among the different varieties of UNIX, but there is more in common than not. Three main processes are run during a login:
- getty - opens a terminal device and prompts for a login name
- login - obtains the user password, performs authentication, and launches a shell
- shell - runs through a series of configuration scripts establishing the users environment.
Part One: The getty Process
The getty program is launched by the init program at startup and whenever
the getty process is terminated (respawn). getty uses the configuration file,
/etc/issue to advertise the system to the user.
- Log on as root on terminal tty1 (<Ctrl><Alt>F1)
Note the message above the login: prompt, and note any other messages you receive
prior to arriving at the shell prompt.
- View the file /etc/issue
How does it compare to what you saw on the screen prior to logging in?
- View the manual page for mingetty to discover the meaning of the
various escape characters that can be used in the issue file.
- Back up the existing /etc/issue file to /etc/issue.00, and
replace the architecture type with the tty (line) number, and add a third line
that gives the current date.
- Log off and note the changes you made.
Note: the other virtual ttys will not change until they are respawned, i.e. after you
log on and off.
- Log back on and list all the getty processes that are running
ps -e | grep getty
Note: the getty program that Linux uses on the console is: mingetty
Why is there no getty program on tty1?
- Jot down the PID number of the mingetty running on tty3
- Switch screen to virtual terminal tty3 (<Ctrl><Alt>F3), and type
root followed by the enter key, but don't type the password.
- Switch back to tty1 and rerun the ps command from above.
Note that mingetty is no longer running on tty3.
- Now grep the process listing for the login processes:
ps -e | grep login
How does the PID number of the login process on tty3 compare to the getty PID you noted above?
How does one process become another process withour changing its PID?
- After a short period of time, the login process on tty3 will timeout,
and a new mingetty process will be spawned by init.
Part Two: The Login Process
In this procedure you will observe the steps taken by the login process in authenticating
the user and in posting such messages as the last time the user logged in, the message
of the day (motd), and the ubiquitous, "You have mail" message.
- Make a backup of the /etc/motd file to /etc/motd.00 and add a mesage
of the day of your own choosing to that file.
- Send a mail mesage from root to root, but don't read the message you send.
- Log off the system and log back in again as root, noting the messages the login
program gives you. Note: Login starts with the Password: prompt.
- Now that you are logged in and have noted the last time you logged in, the message
of the day, and the fact that you have new mail, create the hidden file .hushlogin
in root's home directory:
touch .hushlogin
- Log off and back in again, and note that you don't have to put up with noisy announcements.
This is yet another way that UNIX empowers the user.
- Let's look at the authentication part of login. Authentication is handled by the
PAM modules in /etc/pam.d. (PAM = Pluggable Authentication Modules).
cd /etc/pam.d
- Display the contents of the login file in this directory. We are going to
investigate the first three lines dealing with authentication.
- Comment the second auth line in the file by inserting a comment character (#)
in front of the line:
#auth include system-auth
- After saving the file's contents, log off and back on again.
What is the difference?
- Remove the comment character from second auth line in the file /etc/pam.d/login.
Note the first auth line requiring the pam_securetty PAM module, and the
third line requiring the pam_nologin module.
- Change directory to /etc and edit the file /etc/securetty.
- Place a comment character (#) in front of the tty1 line in this file:
#tty1
Save the file, Log off, and log back on again.
- tty1 is no longer considered secure for root logins! Don't worry, you can
log in on tty2 and fix the problem by removing the comment from the securetty file.
- Create the file /etc/nologin with text such as the following:
echo "No more logins allowed until further notice. -SA" > /etc/nologin
- Switch to a different tty, and login as a regular user, using your personal account.
Can root login?
- Login as root and remove the /etc/nologin file.
- The last task of the login process is to launch the user's shell as defined
in the /etc/passwd file.
Part Three: The Shell Process
In this procedure you will observe how the user's shell environment is established from both
a system perspective as well as incorporating user customization.
- Your shell is a child process of the login process that came from the getty
running on your tty. Observe the PID and PPID of your shell and it's parent:
ps -f
ps -f PPID # where PPID is the PPID number of your bash shell
- All login shells execute the /etc/profile shell script to initialize
system-wide environment variables. Display this file, and note the variables that
are initialized. Note how the root account gets additional paths added to its PATH variable.
Near the bottom of the file you may be able to pick out how the shell scripts in the
directory ./etc/profile.d get executed in turn. List the scripts in the profile.d
directory:
ls /etc/profile.d
- After system initialization comes user customization. In the case of the bash
shell, the hidden file, .bash_profile in the user's home directory is executed.
This in turn, makes calls to other scripts such as .bashrc. Review these files.
- Below are six events that take place during the initialization of the shell's
environment. Your task is to enter these six events into a file called order,
such that events occur in the order that they are executed when a user logs in.
In other words, you must find where and when these commands are executed. The order
they are listed below is random:
- PS1 variable gets initialized specifying what shell prompt the user gets.
- The ls command is aliased to show files in different colors
- The user's umask is set, e.g. umask 002
- The location of the user's system mailbox is determined
- The rm command is aliased to "rm -i"
- The user's $HOME/bin directory is added to the PATH variable
To turn in
lab6x should be the concatenation of three files:
- /etc/issue
- /etc/motd
- order, where order is an ordered listing of the events itemized in Part 3.
Now copy the lab6x file to your account on opus.cabrillo.edu using the following command:
scp lab6x logname@opus.cabrillo.edu:
Cleanup
You should now restore your configuration files by taking care of the following tasks:
- mv /etc/issue.00 /etc/issue
- mv /etc/motd.00 /etc/motd
- rm /root/.hushlogin