login command in UNIX

Posted in

login command in UNIX
vinaykhatri

Vinay Khatri
Last updated on June 16, 2024

    Creating new sessions and logging in are typical tasks while working with UNIX systems, especially if numerous individuals are working on the same workstation. The necessary user credentials and permissions must be stored in the database by the operating system. In this article, we will look at the login command, which assists the operating system in performing the tasks listed above. We'll also go through what events occur when you type this command and hit enter.

    What does the login command do?

    This command is used to create a new session in your UNIX Operating System. Only the users who are present on the machine can be logged in using this command. We can even specify the Environment Variables for a user while writing this command. The environment variables can be specified as a key-value pair in the command. This command is an alternative to the user switching commands in UNIX. The syntax for the command is:

    $ login [options] username

    This command requires root access. If no argument is provided with the command, this command will prompt you for the username.

    The sequence of Events for the command

    Account Checking

    The Operating System ensures that the logins for the specified user are enabled properly and other authentication schemes are enabled.

    Authentication

    The credentials of the user are verified against the database. The user provides a new password if the previous password is expired by any chance.

    Credentials Establishment

    The Operating System verifies all the access rights and permissions for the specified user.

    Session Initialization

    The Operating System initiates the session, including environment variables specified by the users.

    Flags associated with the command

    -h

    This is used to specify the user on a remote server. This is a useful flag associated with this command that allows you to login on remote servers and machines with your terminal.

    -p

    To specify the Operating System to not delete environment variables

    -f

    To tell that the user has already logged in and this avoids entering the password again.

    Directories and related information stored in them

    /usr/sbin/login login command is present here
    /etc/utmp account related information is present here
    /etc/passwd This place contains the respective passwords
    /etc/environment Environment configuration related data is stored here
    /etc/security/lastlog Contains the data regarding recent login attempts
    /etc/security/failedlogin Contains the data regarding unsuccessful logics

    Conclusion

    This article went through the description of the login command in UNIX. This command is helpful in creating sessions with the existing users in the database. It even provides features such as remote login, and caching passwords of users to avoid logging in again and again. We also went through the directories and the related information contained in them.

    People are also reading:

    Leave a Comment on this Post

    0 Comments