Terminal Login
These logins always came through a terminal device driver in the kernel. A host had a fixed number of these terminal devices, so there was a known upper limit on the number of simultaneous logins.
When the system is bootstrapped, the kernel creates process ID 1, the init process, and it is init that brings the system up in multiuser mode. The init process reads the file /etc/ttys and, for every terminal device that allows a login, does a fork followed by an exec of the program getty . Then getty outputs someting like login: and waits for user input username. This gives us the processes shown in Figure
If we log in correctly, login will
- Change to our home directory (chdir )
- Change the ownership of our terminal device (chown ) so we own it
- Change the access permissions for our terminal device so we have permission to read from and write to it
- Set our group IDs by calling setgid and initgroups
- Initialize the environment with all the information that login has: our home directory (HOME ), shell (SHELL ), user name (USER and LOGNAME ), and a default path (PATH )
- Change to our user ID (setuid ) and invoke our login shell, as in execl("/bin/sh", "-sh", (char * )0);
At this point, our login shell is running. Its parent process ID is the original init process (process ID 1), so when our login shell terminates, init is notified (it is sent a SIGCHLD signal) and it starts the whole procedure over again for this terminal. File descriptors 0, 1, and 2 for our login shell are set to the terminal device.
Network Login
The main (physical) difference between logging in to a system through a serial terminal and logging in to a system through a network is that the connection between the terminal and the computer isn’t point-to-point.
To allow the same software to process logins over both terminal logins and network logins, a software driver called a pseudo terminal is used to emulate the behavior of a serial terminal and map terminal operations to network operations, and vice versa.