login Command in Linux

Introduction

This tutorial provides a comprehensive guide to the Linux login command, a fundamental tool for system administration. We will delve into the syntax, usage, and practical applications of this command. Learn how to effectively use login to access user accounts, including logging in as a standard user and, with caution, as the root user. This guide is essential for systemadmin professionals and anyone managing a Linux system, enabling them to understand and utilize the login command for seamless system access and task execution.

We begin with an explanation of the login command's syntax and available options. Then, we demonstrate the procedure for logging in as a typical user, which involves entering login followed by your username and password when prompted. Lastly, the tutorial details logging in as the root user, emphasizing the elevated privileges and associated responsibilities required for this powerful account.

Understanding the login Command

In this section, we will explore the crucial login command within the Linux environment. This command is the primary method for users and system administrators to authenticate and gain access to the system.

Let's start by understanding the basic structure of the login command:

login [options] [username]

The login command offers several options. For instance, -p preserves the environment variables, -h specifies the host, and -f bypasses authentication for a forced login. These options allow for customization of the login process.

To log in as a regular user, simply execute the login command. You'll be prompted for your username and then your password:

$ login
Username: labex
Password:

Example output:

Last login: Thu Apr 13 10:30:00 UTC 2023 on pts/0
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-69-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

This system has been minimized by removing packages and services to reduce
security risks and improve performance. If you need to restore functionality
please use the 'sudo apt-get install -y ubuntu-standard' command.

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

labex@ubuntu:~/project$

As you can see in the output, the user labex has successfully gained access to the system.

Logging in as a Regular User

This section will guide you through the process of logging in to a Linux system as a standard user.

As previously mentioned, the login command is your entry point. To log in as a standard user, type login and provide your username and password when requested:

$ login
Username: labex
Password:

Example output:

Last login: Thu Apr 13 10:30:00 UTC 2023 on pts/0
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-69-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

This system has been minimized by removing packages and services to reduce
security risks and improve performance. If you need to restore functionality
please use the 'sudo apt-get install -y ubuntu-standard' command.

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

labex@ubuntu:~/project$

The example output confirms that the user labex is now logged in as a regular user.

Logging in as the Root User

This section explains how to log in as the root user on a Linux system. The root user, also known as the superuser, has unrestricted privileges and access to the entire system.

To log in as root, utilize the login command with the root username:

$ login root
Password:

Example output:

Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-69-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

This system has been minimized by removing packages and services to reduce
security risks and improve performance. If you need to restore functionality
please use the 'sudo apt-get install -y ubuntu-standard' command.

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

root@ubuntu:~/project#

The output verifies a successful login as the root user. Observe that the command prompt has changed to root@ubuntu:~/project#, signifying the root user's context.

For enhanced security, it's best practice to use the sudo command instead of directly logging in as root. This approach helps to minimize the risk of accidental or malicious damage to the system and promotes more controlled access.

Summary

In this tutorial, we covered the Linux login command, a crucial tool for system access. We explored its syntax and demonstrated how to log in as a standard user by using login and providing the required credentials. Furthermore, we discussed logging in as the root user, emphasizing the necessary precautions and recommending the use of sudo instead. This guide provides practical knowledge of the login command for system administrators and users alike, empowering them to effectively manage access and perform tasks on Linux systems.

400+ Linux Commands