{"id":6628,"date":"2024-01-08T09:23:39","date_gmt":"2024-01-08T16:23:39","guid":{"rendered":"https:\/\/ioflood.com\/blog\/?p=6628"},"modified":"2024-01-08T09:24:13","modified_gmt":"2024-01-08T16:24:13","slug":"install-last-command-linux","status":"publish","type":"post","link":"https:\/\/ioflood.com\/blog\/install-last-command-linux\/","title":{"rendered":"How to Install &#8216;last&#8217; Command | Linux User&#8217;s Guide"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"alignright size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/ioflood.com\/blog\/wp-content\/uploads\/2024\/01\/Digital-illustration-of-a-Linux-terminal-depicting-the-installation-of-the-last-command-used-for-displaying-last-logged-in-users-300x300.jpg\" alt=\"Digital illustration of a Linux terminal depicting the installation of the last command used for displaying last logged-in users\" width=\"300\" height=\"300\" title=\"\"><\/figure>\n<\/div>\n<p>Do you need to install the &#8216;last&#8217; command on your Linux system but aren&#8217;t sure where to start? Many Linux users, might find the task intimidating, but the &#8216;last&#8217; command is an essential utility worth mastering. The command enhances system monitoring, making it easier to manage user logins on your Linux system. It&#8217;s also accessible on most package management systems, simplifying the installation once you understand the process.<\/p>\n<p><strong>In this guide, we will navigate the process of installing the &#8216;last&#8217; command on your Linux system.<\/strong> We are going to provide you with installation instructions for Debian, Ubuntu, CentOS, and AlmaLinux, delve into how to compile the &#8216;last&#8217; command from the source, and install a specific version. Finally, we will show you how to use the &#8216;last&#8217; command and ascertain that the correctly installed version is in use.<\/p>\n<p>Let&#8217;s get started with the step-by-step &#8216;last&#8217; command installation on your Linux system!<\/p>\n<h2>TL;DR: How Do I Install and Use the &#8216;last&#8217; Command in Linux?<\/h2>\n<blockquote><p>\n  In most Linux distributions, the &#8216;last&#8217; command comes pre-installed, you can verify this by calling the command, <code>last<\/code>. If it isn&#8217;t installed, you can add it via the &#8216;sysvinit-tools&#8217; package and the commands, <code>sudo yum install sysvinit-tools<\/code> or <code>sudo apt-get install sysvinit-utils<\/code>. To use it, simply open your terminal and type <code>last<\/code>. This command will display a list of the last logged in users.\n<\/p><\/blockquote>\n<p>For example:<\/p>\n<pre><code class=\"language-bash line-numbers\">last\n\n# Output:\n# username pts\/0        192.168.1.10     Mon Sep 27 09:10   still logged in\n# username pts\/0        192.168.1.10     Mon Sep 27 08:50 - 09:10  (00:20)\n<\/code><\/pre>\n<p>This output shows the username, the terminal where the user was logged in, the IP address from where the user accessed the system, the login time, and the duration of the session.<\/p>\n<p>This is just a basic way to use the &#8216;last&#8217; command in Linux, but there&#8217;s much more to learn about using &#8216;last&#8217; and tracking user logins. Continue reading for more detailed information and advanced usage scenarios.<\/p>\n<h2>Understanding and Installing the &#8216;last&#8217; Command in Linux<\/h2>\n<p>The &#8216;last&#8217; command is a powerful tool in Linux that provides a historical view of user logins. It reads from the <code>\/var\/log\/wtmp<\/code> file, which contains all logins and logouts history. By using this command, you can easily track user activity, making it an essential tool for system administrators. Let&#8217;s explore how to install the &#8216;last&#8217; command using package managers like <code>apt<\/code> and <code>yum<\/code>.<\/p>\n<h3>Installing &#8216;last&#8217; Command with apt<\/h3>\n<p>If you&#8217;re using a Debian-based Linux distribution like Ubuntu, you can use the <code>apt<\/code> package manager to install the &#8216;last&#8217; command. However, in most cases, it comes pre-installed. You can check if it exists by typing <code>last<\/code> in your terminal. If it&#8217;s not installed, you can use the following command:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo apt-get update\nsudo apt-get install sysvinit-utils\n\n# Output:\n# Reading package lists... Done\n# Building dependency tree\n# Reading state information... Done\n# sysvinit-utils is already the newest version (2.96-6ubuntu1).\n<\/code><\/pre>\n<p>This command will update your package lists and install the &#8216;last&#8217; command if it&#8217;s not already present on your system.<\/p>\n<h3>Installing &#8216;last&#8217; Command with yum<\/h3>\n<p>For CentOS, Fedora, or other RedHat-based distributions, you can use the <code>yum<\/code> package manager. Similar to <code>apt<\/code>, the &#8216;last&#8217; command usually comes pre-installed. If it&#8217;s not, you can install it by typing:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo yum update\nsudo yum install sysvinit-tools\n\n# Output:\n# Loaded plugins: fastestmirror\n# Loading mirror speeds from cached hostfile\n# Package sysvinit-tools-2.88-14.dsf.el7.x86_64 already installed and latest version\n# Nothing to do\n<\/code><\/pre>\n<p>This command will update your package lists and install the &#8216;last&#8217; command if it&#8217;s not already present on your system.<\/p>\n<p>In the next section, we&#8217;ll dive into alternative installation methods of the &#8216;last&#8217; command.<\/p>\n<h2>Installing &#8216;last&#8217; Command from Source Code<\/h2>\n<p>Sometimes, you might need to install the &#8216;last&#8217; command from source code. This approach is useful when you want to install a specific version of the command, or when the command is not available in your distribution&#8217;s package repository.<\/p>\n<p>To install from source, first, you need to download the source code. You can usually find it on the software&#8217;s official website or a public repository like GitHub. Once downloaded, you can compile and install it using the <code>make<\/code> and <code>make install<\/code> commands.<\/p>\n<pre><code class=\"language-bash line-numbers\">wget http:\/\/example.com\/last-command-source.tar.gz\n\ntar -xvzf last-command-source.tar.gz\n\ncd last-command-source\n\nmake\n\nsudo make install\n\n# Output:\n# [Expected output from command]\n<\/code><\/pre>\n<p>This will compile the &#8216;last&#8217; command from the source and install it on your system.<\/p>\n<h2>Installing Different Versions of &#8216;last&#8217; Command<\/h2>\n<h3>From Source<\/h3>\n<p>To install a specific version of the &#8216;last&#8217; command from source, you would need to download the source code for that version. Then, you would compile and install it the same way as described above.<\/p>\n<h3>Using Package Managers<\/h3>\n<h4>apt<\/h4>\n<p>If you&#8217;re using apt, you can list all available versions of a package using the <code>apt-cache madison<\/code> command, and then install a specific version using the <code>apt-get install<\/code> command followed by the package name and the version number.<\/p>\n<pre><code class=\"language-bash line-numbers\">apt-cache madison sysvinit-utils\n\nsudo apt-get install sysvinit-utils=2.96-6ubuntu1\n\n# Output:\n# [Expected output from command]\n<\/code><\/pre>\n<h4>yum<\/h4>\n<p>If you&#8217;re using yum, you can list all available versions of a package using the <code>yum --showduplicates list<\/code> command, and then install a specific version using the <code>yum install<\/code> command followed by the package name and the version number.<\/p>\n<pre><code class=\"language-bash line-numbers\">yum --showduplicates list sysvinit-tools\n\nsudo yum install sysvinit-tools-2.88-14.dsf.el7.x86_64\n\n# Output:\n# [Expected output from command]\n<\/code><\/pre>\n<h3>Version Comparison<\/h3>\n<table>\n<thead>\n<tr>\n<th>Version<\/th>\n<th>Key Changes\/Features<\/th>\n<th>Compatibility<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2.96<\/td>\n<td>Feature 1, Feature 2<\/td>\n<td>Ubuntu 20.04<\/td>\n<\/tr>\n<tr>\n<td>2.88<\/td>\n<td>Feature 3, Feature 4<\/td>\n<td>CentOS 7<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Verifying and Using &#8216;last&#8217;<\/h2>\n<h3>Basic Usage<\/h3>\n<p>Once installed, you can use the &#8216;last&#8217; command to view the login history. By default, it displays the history of all users. However, you can specify a username as an argument to view the history of a specific user.<\/p>\n<pre><code class=\"language-bash line-numbers\">last username\n\n# Output:\n# username pts\/0        192.168.1.10     Mon Sep 27 09:10   still logged in\n# username pts\/0        192.168.1.10     Mon Sep 27 08:50 - 09:10  (00:20)\n<\/code><\/pre>\n<h3>Verifying Installation<\/h3>\n<p>You can verify that the &#8216;last&#8217; command is installed and working correctly by simply executing it without any arguments. If it&#8217;s working correctly, it should display the login history.<\/p>\n<pre><code class=\"language-bash line-numbers\">last\n\n# Output:\n# username pts\/0        192.168.1.10     Mon Sep 27 09:10   still logged in\n# username pts\/0        192.168.1.10     Mon Sep 27 08:50 - 09:10  (00:20)\n<\/code><\/pre>\n<p>This output confirms that the &#8216;last&#8217; command is installed correctly and working as expected.<\/p>\n<h2>Exploring Alternative Methods to Track User Logins in Linux<\/h2>\n<p>While the &#8216;last&#8217; command is a powerful tool for tracking user logins in Linux, it&#8217;s not the only one. Other methods, such as using the &#8216;lastlog&#8217; command or analyzing log files, also provide valuable insights into user activity. Let&#8217;s delve into these alternative approaches.<\/p>\n<h3>Using the &#8216;lastlog&#8217; Command<\/h3>\n<p>The &#8216;lastlog&#8217; command displays the most recent login of all users or of a specific user. To use it, simply type &#8216;lastlog&#8217; into your terminal. To view the last login of a specific user, use the command <code>lastlog -u username<\/code>.<\/p>\n<pre><code class=\"language-bash line-numbers\">lastlog -u username\n\n# Output:\n# Username         Port     From             Latest\n# username         pts\/0    192.168.1.10     Mon Sep 27 09:10:00 +0000 2021\n<\/code><\/pre>\n<p>This command displays the username, the terminal from where the user logged in, the IP address, and the time of the last login. Unlike the &#8216;last&#8217; command, &#8216;lastlog&#8217; only shows the most recent login.<\/p>\n<h3>Analyzing Log Files<\/h3>\n<p>Another approach to track user logins is by directly analyzing log files. The <code>\/var\/log\/wtmp<\/code> and <code>\/var\/log\/btmp<\/code> files store login and logout records. You can use commands like <code>less<\/code>, <code>cat<\/code>, or <code>more<\/code> to view these files, or <code>grep<\/code> to search them.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo less \/var\/log\/wtmp\n\n# Output:\n# [Expected output from command]\n<\/code><\/pre>\n<p>This command will display the contents of the &#8216;wtmp&#8217; file, which includes login and logout records.<\/p>\n<h3>Comparing Methods<\/h3>\n<table>\n<thead>\n<tr>\n<th>Method<\/th>\n<th>Advantages<\/th>\n<th>Disadvantages<\/th>\n<th>Recommendations<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>last<\/td>\n<td>Displays all logins<\/td>\n<td>Can&#8217;t filter by date<\/td>\n<td>General use<\/td>\n<\/tr>\n<tr>\n<td>lastlog<\/td>\n<td>Displays most recent login<\/td>\n<td>Only shows the latest login<\/td>\n<td>Checking latest logins<\/td>\n<\/tr>\n<tr>\n<td>Log files<\/td>\n<td>Provides raw data<\/td>\n<td>Requires knowledge of log format<\/td>\n<td>Advanced analysis<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In conclusion, the &#8216;last&#8217; command, &#8216;lastlog&#8217; command, and log files analysis each have their own strengths and weaknesses. Depending on your specific needs, you might find one method more useful than the others. However, a comprehensive approach that combines all these methods would provide the most complete view of user logins in Linux.<\/p>\n<h2>Troubleshooting &#8216;last&#8217; Command Issues in Linux<\/h2>\n<p>While using the &#8216;last&#8217; command in Linux, you might encounter some issues. Let&#8217;s discuss some common problems and their solutions.<\/p>\n<h3>Empty Output<\/h3>\n<p>If the &#8216;last&#8217; command returns an empty output, it could mean that the <code>\/var\/log\/wtmp<\/code> file, which stores the login history, is missing or corrupted. You can recreate it using the <code>touch<\/code> command.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo touch \/var\/log\/wtmp\n\n# Output:\n# [No output]\n<\/code><\/pre>\n<p>This command creates a new &#8216;wtmp&#8217; file if it doesn&#8217;t exist, or updates the modification time if it does.<\/p>\n<h3>Permission Denied Error<\/h3>\n<p>If you get a &#8216;Permission denied&#8217; error when trying to view or manipulate the &#8216;wtmp&#8217; file, it means you don&#8217;t have the necessary permissions. You can solve this by using the &#8216;sudo&#8217; command, which elevates your permissions.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo last\n\n# Output:\n# username pts\/0        192.168.1.10     Mon Sep 27 09:10   still logged in\n# username pts\/0        192.168.1.10     Mon Sep 27 08:50 - 09:10  (00:20)\n<\/code><\/pre>\n<p>This command runs the &#8216;last&#8217; command as a superuser, bypassing the permission restrictions.<\/p>\n<h3>Incorrect Time Display<\/h3>\n<p>If the &#8216;last&#8217; command displays the wrong time, it could mean that your system&#8217;s timezone is not set correctly. You can check your current timezone with the <code>date<\/code> command and change it with the <code>tzselect<\/code> command.<\/p>\n<pre><code class=\"language-bash line-numbers\">date\n\n# Output:\n# Mon Sep 27 09:10:00 UTC 2021\n\nsudo tzselect\n\n# Output:\n# [Follow the interactive prompts to select your timezone]\n<\/code><\/pre>\n<p>These commands display your current timezone and allow you to change it, respectively.<\/p>\n<p>Remember, the &#8216;last&#8217; command is a powerful tool, but like any tool, it might require some troubleshooting to get it working perfectly. Don&#8217;t be discouraged if you encounter issues; with a bit of practice and patience, you&#8217;ll be able to master the &#8216;last&#8217; command in Linux.<\/p>\n<h2>Understanding User Management and Security in Linux<\/h2>\n<p>To fully grasp the significance of the &#8216;last&#8217; command, it&#8217;s essential to understand the basics of user management and security in Linux. User management involves creating, deleting, and controlling users and their access to the system. On the other hand, security involves protecting your system from unauthorized access or misuse.<\/p>\n<h3>User Management in Linux<\/h3>\n<p>In Linux, each user has a unique username and user ID. This allows the system to track user activity and control access to resources. You can manage users using commands like <code>useradd<\/code>, <code>usermod<\/code>, and <code>userdel<\/code>.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo useradd newuser\n\n# Output:\n# [No output]\n<\/code><\/pre>\n<p>This command creates a new user called &#8216;newuser&#8217;. You can then set a password for the new user using the <code>passwd<\/code> command.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo passwd newuser\n\n# Output:\n# Enter new UNIX password: \n# Retype new UNIX password: \n# passwd: password updated successfully\n<\/code><\/pre>\n<p>This command sets a password for &#8216;newuser&#8217;. The user can now log in to the system using their username and password.<\/p>\n<h3>Security in Linux<\/h3>\n<p>Security in Linux involves protecting your system from unauthorized access. This is achieved through user permissions, firewalls, and security modules like SELinux. User permissions control who can access what files and directories, while firewalls and security modules protect against network threats.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo chmod 700 \/home\/newuser\n\n# Output:\n# [No output]\n<\/code><\/pre>\n<p>This command changes the permissions of the &#8216;newuser&#8217; home directory, allowing only the owner to read, write, and execute files in it.<\/p>\n<h2>Importance of Tracking User Logins<\/h2>\n<p>Tracking user logins is a crucial aspect of system administration and security. It allows you to monitor who is accessing your system, when, and from where. You can also identify any suspicious activity, such as logins from unknown IP addresses or at unusual times. The &#8216;last&#8217; command is a powerful tool for this purpose, providing a historical view of user logins.<\/p>\n<h2>Exploring User Login Tracking and Security in Linux<\/h2>\n<p>Understanding and tracking user logins in Linux is not just about knowing who is accessing your system. It&#8217;s about maintaining the integrity and security of your system. By monitoring user logins, you can identify anomalies, detect potential threats, and take proactive measures to secure your environment.<\/p>\n<h3>User Groups and Permissions in Linux<\/h3>\n<p>User groups are a fundamental concept in Linux. They are used to manage multiple users, control access to files, and simplify system administration. You can create a user group using the <code>groupadd<\/code> command, add users to the group using the <code>usermod<\/code> command, and set group permissions using the <code>chmod<\/code> command.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo groupadd newgroup\nsudo usermod -aG newgroup newuser\nsudo chmod 770 \/home\/newuser\n\n# Output:\n# [No output]\n<\/code><\/pre>\n<p>These commands create a new group called &#8216;newgroup&#8217;, add &#8216;newuser&#8217; to the group, and set the permissions of the &#8216;newuser&#8217; home directory to allow only the owner and group members to read, write, and execute files in it.<\/p>\n<h3>Importance of User Login Tracking in System Administration and Security<\/h3>\n<p>In system administration, user login tracking is crucial for maintaining system integrity. It allows administrators to monitor system usage, identify potential issues, and take corrective action. In security, user login tracking is essential for detecting unauthorized access and potential threats.<\/p>\n<pre><code class=\"language-bash line-numbers\">last | grep 'unknown'\n\n# Output:\n# unknown  tty1                          Wed Oct  6 12:34 - 12:34  (00:00)\n<\/code><\/pre>\n<p>This command uses the &#8216;last&#8217; command to track user logins and the &#8216;grep&#8217; command to filter out logins from unknown users. If it returns any results, it could indicate unauthorized access.<\/p>\n<h3>Further Resources for Mastering User Login Tracking in Linux<\/h3>\n<ol>\n<li><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.makeuseof.com\/user-management-linux-guide\/\" target=\"_blank\" rel=\"noopener\">Linux User Management<\/a>: This comprehensive guide provides detailed insights and instructions on managing users in Linux systems.<\/p>\n<\/li>\n<li>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/devconnected.com\/linux-file-permissions-complete-guide\/\" target=\"_blank\" rel=\"noopener\">Understanding Linux Permissions and How to Use Them<\/a>: This resource explains the concept of permissions in Linux and demonstrates how to effectively utilize them.<\/p>\n<\/li>\n<li>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.itprotoday.com\/linux\/advanced-linux-user-management-privileges-resource-limits-and-more\" target=\"_blank\" rel=\"noopener\">Advanced Linux Security<\/a>: Dive into advanced Linux security measures with a focus on user management.<\/p>\n<\/li>\n<\/ol>\n<h2>Wrapping Up: Installing the &#8216;last&#8217; Command in Linux<\/h2>\n<p>In this comprehensive guide, we&#8217;ve delved into the depths of the &#8216;last&#8217; command in Linux, an essential tool for tracking user logins. We&#8217;ve learned how to install and use the &#8216;last&#8217; command, and tackled some common issues that you might encounter along the way.<\/p>\n<p>We started with the basics of installing and using the &#8216;last&#8217; command, learning how to view a list of the last logged in users. We then explored more advanced topics, such as installing the &#8216;last&#8217; command from source code, installing specific versions, and verifying the installation.<\/p>\n<p>Finally, we considered alternative approaches to track user logins in Linux, such as using the &#8216;lastlog&#8217; command or analyzing log files directly. We also delved into the fundamentals of user management and security in Linux, and discussed the importance of tracking user logins in system administration and security.<\/p>\n<p>Here&#8217;s a quick comparison of the methods we&#8217;ve discussed:<\/p>\n<table>\n<thead>\n<tr>\n<th>Method<\/th>\n<th>Pros<\/th>\n<th>Cons<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>last<\/td>\n<td>Displays all logins<\/td>\n<td>Can&#8217;t filter by date<\/td>\n<\/tr>\n<tr>\n<td>lastlog<\/td>\n<td>Displays most recent login<\/td>\n<td>Only shows the latest login<\/td>\n<\/tr>\n<tr>\n<td>Log files<\/td>\n<td>Provides raw data<\/td>\n<td>Requires knowledge of log format<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Whether you&#8217;re a beginner just starting out with the &#8216;last&#8217; command or an experienced system administrator looking for a handy reference, we hope this guide has been helpful. With the &#8216;last&#8217; command and the alternative methods we&#8217;ve discussed, you&#8217;re now well-equipped to track user logins in Linux and maintain the integrity and security of your system.<\/p>\n<p>The ability to track user logins is a powerful tool for system administration and security. Now, you&#8217;re ready to enjoy the benefits of this tool and take your Linux skills to the next level. Happy tracking!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you need to install the &#8216;last&#8217; command on your Linux system but aren&#8217;t sure where to start? Many Linux users, might find the task intimidating, but the &#8216;last&#8217; command is an essential utility worth mastering. The command enhances system monitoring, making it easier to manage user logins on your Linux system. It&#8217;s also accessible [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":15531,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[124,3,9],"tags":[],"class_list":["post-6628","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash","category-linux","category-sysadmin","cat-124-id","cat-3-id","cat-9-id","has_thumb"],"_links":{"self":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/6628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/comments?post=6628"}],"version-history":[{"count":9,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/6628\/revisions"}],"predecessor-version":[{"id":15428,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/6628\/revisions\/15428"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media\/15531"}],"wp:attachment":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media?parent=6628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/categories?post=6628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/tags?post=6628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}