Login Process in Linux


When Linux booting process is completed it display the login prompt. There are different process running in Linux when any user login to their shell. these processes are as follows.




Login process steps


Init starts getty process

getty process initiates login prompt on terminal

login command check user credentials from /etc/passwd

getty starts user shell process

shell reads the system wide files /etc/profile, /etc/bashrc

Shell reads user specific files .profile, .login

Now it reads shell specific configuration file .bashrc

Shell displays the default prompt



Init starts getty


When Linux system boots it goes through various booting stages. In last stage it starts init, which reads a file called inittab which is located in /etc, where it find out in which run level it has to execute. Once init process completes run-level execution and executing commands in /etc/rc.local, it will start a process called getty. Getty is the process which will take care of complete login process.



Getty shows login prompt


getty is short for “get terminal”. A getty program initiates login command, it opens the terminal device, initializes it, prints login: and waits for a user name to be entered.



getty starts /etc/login


Once user enters his login name getty starts /ets/login, this in-turn will prompt for user password. The password what user typed will be hidden and will not be shown on screen.



getty verifies the credential and starts users shell


In next stage getty checks the user credentials by verifying it with /etc/passwd and /etc/shadow file, if password matches then it initiates user properties gathering and starts users shell. If password doesn’t match then getty terminates login process and re-initiates again with new login: prompt.

In next stage the getty process reads the user properties (username, UID, GID, home directory, user shell etc.) from /etc/passwd file. After that it reads /etc/motd file for displaying content banner message.



Shell reads system wide default files and specific default files


For getting shell related properties, user aliases and variables getty process reads appropriate system wide default files /etc/profile or /etc/bashrc . After the system wide default files are read the shell reads user specific login files .profile or .login . 



Shell specific file read


At last stage it reads shell specific configuration files (.bashrc, .bash_profile etc. for bash shell) of that user which it gets on the users home directory.



Shell Prompt


When all startup files are read the shell displays the default prompt, normally PS1 prompt for user to execute their commands, here user can type any command to execute.






Login process




No comments: