What happens when we login/logout in Linux

When we login to your UNIX like operating system user account the following three things happen.

1. A new Shell is started

A new shell process will be started for your session. This is the login shell that is assigned to you by the System Administrator. You can get the name of this shell in the /etc/passwd file. This shell acts as a middle-man between the user commands that are typed at the shell prompt and the UNIX kernel. The process id of this shell can be seen by executing the ps -f command as follows.

[[email protected] ~]# ps -f

UID      PID     PPID   C     STIME    TTY      TIME             CMD
root      5694    5791    0     10:44      pts/0    00:00:00     -bash
root      5814    5794    0     10:44      pts/0    00:00:00      ps -f

You can see above a process for the “bash” shell is running in the background. In this case, the PID (Process ID, a unique number assigned to the process) for the shell process is 5694.

2. .bash_profile is executed

The second thing happens when you login is a special file named .bash_profile automatically gets executed. Every user has this file in his/her home directory. Home directory is a directory assigned to each user as his/her home. If you write any UNIX command in this .bash_profile file, it will get executed every time you login. Usually commands like “alias” are written in his .bash_profile file. A sample .bash_profile is shown below.

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
# User specific environment and startup programs
export PATH
alias rm='rm -i'
echo "-----------------------------------------"
echo "Welcome $USER"
echo "-----------------------------------------"

3. You are put into your HOME directory

A HOME directory is assigned to every user by the System Administrator. You can find the name of the home of your HOME directory in the /etc/passwd file. The third thing happens when users log into their account, automatically they put into their HOME directory. You can check this by typing the “pwd” command immediately after you login. HOME directory is where the user has the privileges to create/modify any file or directory.

Welcome root
[[email protected] ~]# pwd
/root <-- This is your HOME directory
[[email protected] ~]#

Read More : Basic Overview of UNIX/Linux Operating System

Share on:

Ravindra Kumar

Hi, This is Ravindra. I am founder of TheCodeCloud. I am AWS Certified Solutions Architect Associate & Certified in Oracle Cloud as well. I am DevOps and Data Science Enthusiast.

Recommended Reading..

Leave a Comment