The “login” command in Linux is used to initiate a new login session on the system. It prompts for a username and password, authenticates the user, and starts a new session with the user’s environment and privileges.
Here is the basic syntax of the “login” command:
login [options] [username]
Here’s a practical example of how to use the “login” command:
- Start a new login session:
login
Running the “login” command without any options prompts you to enter a username and password to start a new login session. Once authenticated, it starts a new shell session with the user’s environment and privileges.
Example:
$ login
Login: john
Password:
Last login: Sat May 22 18:12:01 PDT 2023 on tty1
Welcome to Linux!
[john@localhost ~]$
In this example, executing the “login” command initiates a new login session for the user “john”. The user is prompted to enter the username and password, and upon successful authentication, a new shell session is started.
- Start a login session with a specific user:
login username
Replace “username” with the actual username of the user with whom you want to start a login session. This command will directly prompt for the password of the specified user and initiate a session with their environment.
Example:
$ login jane
Password:
Last login: Fri May 21 09:28:12 PDT 2023 on pts/0
Welcome back, Jane!
[jane@localhost ~]$
In this example, the “login” command is used to start a login session for the user “jane” directly, without prompting for a username. After entering the password, the user’s shell session is initiated.
Please note that the “login” command typically requires root or administrative privileges to start a new login session for another user. Regular users can use the command to initiate a new session for themselves without specifying a username.
Use the “login” command with caution, especially when starting login sessions for other users, as it requires appropriate permissions and can potentially interrupt existing sessions.