{"id":6563,"date":"2024-01-02T12:21:37","date_gmt":"2024-01-02T19:21:37","guid":{"rendered":"https:\/\/ioflood.com\/blog\/?p=6563"},"modified":"2024-01-02T12:22:02","modified_gmt":"2024-01-02T19:22:02","slug":"install-chage-command-linux","status":"publish","type":"post","link":"https:\/\/ioflood.com\/blog\/install-chage-command-linux\/","title":{"rendered":"How to Install and Use the &#8216;chage&#8217; Command in Linux"},"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-chage-command-used-for-changing-user-password-expiry-information-300x300.jpg\" alt=\"Digital illustration of a Linux terminal depicting the installation of the chage command used for changing user password expiry information\" width=\"300\" height=\"300\" title=\"\"><\/figure>\n<\/div>\n<p>Are you struggling with managing password expiration in your Linux system? You&#8217;re not alone. Many Linux users, especially beginners, find this task a bit daunting. But, the &#8216;chage&#8217; command is here to help. Like a vigilant security guard, it assists you in managing password expiration policies effectively. It&#8217;s also readily available on most package management systems, making the process straightforward once you know how to do it.<\/p>\n<p><strong>In this guide, we will walk you through the process of installing and using the &#8216;chage&#8217; command in Linux.<\/strong> We will show you methods for both APT and YUM-based distributions like Debian, Ubuntu, CentOS, and AlmaLinux. We will also delve into advanced topics like compiling from source and installing a specific version. Finally, we will wrap up with guidance on how to use the &#8216;chage&#8217; command and verify the correct version is installed.<\/p>\n<p>So, let&#8217;s dive in and start installing &#8216;chage&#8217; on your Linux system!<\/p>\n<h2>TL;DR: How Do I Install and Use the &#8216;chage&#8217; Command in Linux?<\/h2>\n<blockquote><p>\n  The <code>'chage'<\/code> command is typically pre-installed on most Linux distributions. However, if it&#8217;s not present, you can install it using your distribution&#8217;s package manager. For Debian-based distributions like Ubuntu, you can use the command <code>sudo apt-get install passwd<\/code>.\n<\/p><\/blockquote>\n<pre><code class=\"language-bash line-numbers\">sudo apt-get update\nsudo apt-get install passwd\n\n# Output:\n# Reading package lists... Done\n# Building dependency tree\n# Reading state information... Done\n# passwd is already the newest version (1:4.8.1-1ubuntu5.20.04).\n# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n<\/code><\/pre>\n<p>This command updates your package list and installs the &#8216;passwd&#8217; package, which includes the &#8216;chage&#8217; command. The output indicates whether the package is already installed or if it has been newly installed.<\/p>\n<p>This is just a basic way to install the &#8216;chage&#8217; command in Linux, but there&#8217;s much more to learn about installing and using &#8216;chage&#8217;. Continue reading for more detailed information and advanced usage scenarios.<\/p>\n<h2>Understanding and Installing the &#8216;chage&#8217; Command<\/h2>\n<p>Before diving into the installation process, let&#8217;s understand what &#8216;chage&#8217; is and why it&#8217;s essential for Linux users. The &#8216;chage&#8217; command allows you to view and modify the password aging information for a user. It&#8217;s a handy tool for system administrators to manage password expiration policies effectively. The main purpose of &#8216;chage&#8217; is to ensure the security of a system by enforcing regular password changes.<\/p>\n<h3>Installing &#8216;chage&#8217; with APT<\/h3>\n<p>In Debian-based systems like Ubuntu, we use the APT (Advanced Package Tool) package manager to install the &#8216;chage&#8217; command. If it&#8217;s not already installed, you can add it using the following commands:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo apt update\nsudo apt install passwd\n\n# Output:\n# Reading package lists... Done\n# Building dependency tree\n# Reading state information... Done\n# passwd is already the newest version (1:4.8.1-1ubuntu5.20.04).\n# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n<\/code><\/pre>\n<p>The first command updates your package list, and the second command installs the &#8216;passwd&#8217; package, which includes the &#8216;chage&#8217; command. The output indicates whether the package is already installed or if it has been newly installed.<\/p>\n<h3>Installing &#8216;chage&#8217; with YUM<\/h3>\n<p>For CentOS and other Red Hat-based distributions, we use the YUM (Yellowdog Updater, Modified) package manager. To install the &#8216;chage&#8217; command, you can use the following commands:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo yum check-update\nsudo yum install shadow-utils\n\n# Output:\n# Loaded plugins: fastestmirror\n# Loading mirror speeds from cached hostfile\n# Package shadow-utils-4.6-5.el7.x86_64 already installed and latest version\n# Nothing to do\n<\/code><\/pre>\n<p>The first command checks for updates, and the second command installs the &#8216;shadow-utils&#8217; package, which includes the &#8216;chage&#8217; command. The output shows whether the package is already installed or if it has been newly installed.<\/p>\n<p>By following these steps, you should now have the &#8216;chage&#8217; command installed on your Linux system. In the next section, we&#8217;ll explore how to use this command to manage password expiration policies.<\/p>\n<h2>Installing &#8216;chage&#8217; from Source Code<\/h2>\n<p>If you prefer to install the &#8216;chage&#8217; command from source code, you need to download the source code of the &#8216;shadow&#8217; package, which contains the &#8216;chage&#8217; command. Here&#8217;s how you can do it:<\/p>\n<pre><code class=\"language-bash line-numbers\">wget https:\/\/github.com\/shadow-maint\/shadow\/releases\/download\/4.8.1\/shadow-4.8.1.tar.xz\n\n# Output:\n# `shadow-4.8.1.tar.xz` saved\n<\/code><\/pre>\n<p>This command downloads the source code of the &#8216;shadow&#8217; package. The output confirms the successful download of the package.<\/p>\n<p>Next, you need to extract the downloaded package and compile it:<\/p>\n<pre><code class=\"language-bash line-numbers\">tar -xf shadow-4.8.1.tar.xz\ncd shadow-4.8.1\n.\/configure\nmake\nsudo make install\n\n# Output:\n# Making install in man\n# make[1]: Entering directory '\/home\/user\/shadow-4.8.1\/man'\n# make[2]: Entering directory '\/home\/user\/shadow-4.8.1\/man'\n# make[2]: Nothing to be done for 'install-exec-am'.\n# make[2]: Nothing to be done for 'install-data-am'.\n# make[2]: Leaving directory '\/home\/user\/shadow-4.8.1\/man'\n# make[1]: Leaving directory '\/home\/user\/shadow-4.8.1\/man'\n<\/code><\/pre>\n<p>The commands extract the package, navigate into the package directory, configure the package for your system, compile the package, and finally install it. The output shows the successful installation of the package.<\/p>\n<h2>Installing Different Versions of &#8216;chage&#8217;<\/h2>\n<p>There are various versions of the &#8216;chage&#8217; command available, and each version comes with different features. Depending on your specific needs, you might want to install a different version of &#8216;chage&#8217;. Here&#8217;s a comparison of some versions:<\/p>\n<table>\n<thead>\n<tr>\n<th>Version<\/th>\n<th>Key Features<\/th>\n<th>Compatibility<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>4.8.1<\/td>\n<td>Latest security patches, New features<\/td>\n<td>All latest distributions<\/td>\n<\/tr>\n<tr>\n<td>4.2.1<\/td>\n<td>Stable, Fewer features<\/td>\n<td>Older distributions<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Installing Different Versions from Source<\/h3>\n<p>To install a different version from source, you need to download the source code of the desired version and follow the same steps as above. Replace &#8216;4.8.1&#8217; with your desired version in the &#8216;wget&#8217; command.<\/p>\n<h3>Installing Different Versions Using Package Managers<\/h3>\n<h4>Using APT<\/h4>\n<p>For APT, you can specify the version number while installing the package. However, only certain versions might be available in the repositories.<\/p>\n<h4>Using YUM<\/h4>\n<p>For YUM, you can enable the repository containing the desired version and then install the package.<\/p>\n<h2>Basic Examples of Using &#8216;chage&#8217; and Verifying Its Installation<\/h2>\n<h3>Using &#8216;chage&#8217;<\/h3>\n<p>You can use the &#8216;chage&#8217; command to set the password expiry date for a user. Here&#8217;s how you can do it:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo chage -M 30 username\n\n# Output:\n# Changing the aging information for username\n# Password expires: Aug 30, 2022\n<\/code><\/pre>\n<p>This command sets the password of the user &#8216;username&#8217; to expire after 30 days. The output confirms the successful change of the password expiry date.<\/p>\n<h3>Verifying the Installation of &#8216;chage&#8217;<\/h3>\n<p>You can verify the successful installation of &#8216;chage&#8217; by checking its version:<\/p>\n<pre><code class=\"language-bash line-numbers\">chage --version\n\n# Output:\n# chage from shadow 4.8.1\n<\/code><\/pre>\n<p>This command displays the version of the installed &#8216;chage&#8217; command. The output confirms the successful installation of the command.<\/p>\n<h2>Exploring Alternative Methods for Managing Password Expiration<\/h2>\n<p>While &#8216;chage&#8217; is an incredibly useful tool for managing password expiration in Linux, it&#8217;s not the only option available. Let&#8217;s explore some alternative methods you can use to achieve the same goal.<\/p>\n<h3>Using the &#8216;passwd&#8217; Command<\/h3>\n<p>The &#8216;passwd&#8217; command is another powerful tool for managing password expiration. With this command, you can change the password of a user, as well as set the password expiry date.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo passwd -e username\n\n# Output:\n# Expiring password for user username.\n# passwd: Success\n<\/code><\/pre>\n<p>This command immediately expires the password for the user &#8216;username&#8217;. The user will be prompted to change their password the next time they log in.<\/p>\n<h3>Manually Editing the &#8216;\/etc\/shadow&#8217; File<\/h3>\n<p>For more advanced users, you can manually edit the &#8216;\/etc\/shadow&#8217; file to manage password expiration. This file contains the password information for all users.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo nano \/etc\/shadow\n\n# Output:\n# username:encrypted-password:17855:0:99999:7:::\n<\/code><\/pre>\n<p>This command opens the &#8216;\/etc\/shadow&#8217; file in a text editor. The third field is the date of the last password change, and the fifth field is the maximum number of days between password changes.<\/p>\n<p>However, manually editing the &#8216;\/etc\/shadow&#8217; file is risky and should only be done by experienced users. A single mistake can cause serious issues.<\/p>\n<h3>Weighing Your Options<\/h3>\n<p>Each method has its benefits and drawbacks. The &#8216;chage&#8217; command is easy to use and comes pre-installed on most Linux distributions. The &#8216;passwd&#8217; command offers similar functionality but is more versatile. Manually editing the &#8216;\/etc\/shadow&#8217; file gives you the most control but is also the most risky.<\/p>\n<p>The best method depends on your specific needs and level of expertise. Regardless of the method you choose, always remember to follow best practices to ensure the security of your system.<\/p>\n<h2>Troubleshooting &#8216;chage&#8217; Command Issues<\/h2>\n<p>While &#8216;chage&#8217; is a robust and reliable command, you may occasionally encounter issues or errors. Here are some common problems and their solutions.<\/p>\n<h3>&#8216;chage: command not found&#8217; Error<\/h3>\n<p>If you get a &#8216;chage: command not found&#8217; error, it means the &#8216;chage&#8217; command is not installed on your system. You can install it using your package manager, as we discussed earlier.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo apt update\nsudo apt install passwd\n\n# Output:\n# Reading package lists... Done\n# Building dependency tree\n# Reading state information... Done\n# passwd is already the newest version (1:4.8.1-1ubuntu5.20.04).\n# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n<\/code><\/pre>\n<p>This command updates your package list and installs the &#8216;passwd&#8217; package, which includes the &#8216;chage&#8217; command. The output indicates whether the package is already installed or if it has been newly installed.<\/p>\n<h3>&#8216;chage: Permission denied&#8217; Error<\/h3>\n<p>If you get a &#8216;chage: Permission denied&#8217; error, it means you don&#8217;t have the necessary permissions to run the &#8216;chage&#8217; command. You can solve this problem by using &#8216;sudo&#8217; to run the command as the root user.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo chage -l username\n\n# Output:\n# Last password change                                    : Feb 02, 2022\n# Password expires                                        : never\n# Password inactive                                       : never\n# Account expires                                         : never\n# Minimum number of days between password change          : 0\n# Maximum number of days between password change          : 99999\n# Number of days of warning before password expires       : 7\n<\/code><\/pre>\n<p>This command displays the password aging information for the user &#8216;username&#8217;. The output confirms the successful execution of the command.<\/p>\n<h2>Best Practices for Using &#8216;chage&#8217;<\/h2>\n<p>While &#8216;chage&#8217; is a powerful tool, it&#8217;s essential to use it responsibly. Always remember to use &#8216;sudo&#8217; when necessary, and avoid changing the password expiration policies without a valid reason. Regularly updating your system and the &#8216;chage&#8217; command can also help prevent issues.<\/p>\n<h2>Understanding Password Management in Linux<\/h2>\n<p>In Linux, password management is a fundamental aspect of system security. It involves creating, changing, and expiring passwords. The &#8216;chage&#8217; command plays an essential role in this process, allowing system administrators to manage password expiration policies effectively.<\/p>\n<h3>Importance of Password Expiration Policies<\/h3>\n<p>Password expiration policies are crucial for maintaining the security of a Linux system. They force users to change their passwords regularly, preventing unauthorized access from those who might have learned their passwords. Additionally, regular password changes can limit the damage if a password is compromised without the user&#8217;s knowledge.<\/p>\n<pre><code class=\"language-bash line-numbers\">chage -l username\n\n# Output:\n# 'username' password expires: Aug 30, 2022\n<\/code><\/pre>\n<p>This command checks when the password for the user &#8216;username&#8217; will expire. The output shows the expiry date, indicating the effectiveness of the password expiration policy.<\/p>\n<h3>Role of the &#8216;chage&#8217; Command<\/h3>\n<p>The &#8216;chage&#8217; command is a powerful tool for managing password expiration policies. It allows you to change the number of days between password changes, set a password to expire after a certain period, and even lock a user&#8217;s password.<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo chage -M 30 username\n\n# Output:\n# Changing the aging information for username\n# Password expires: Aug 30, 2022\n<\/code><\/pre>\n<p>This command sets the password of the user &#8216;username&#8217; to expire after 30 days. The output confirms the successful change of the password expiry date. This example demonstrates the power of the &#8216;chage&#8217; command in enforcing password expiration policies.<\/p>\n<p>By understanding the importance of password expiration policies and the role of the &#8216;chage&#8217; command, you can ensure the security of your Linux system.<\/p>\n<h2>Expanding Your Use of the &#8216;chage&#8217; Command<\/h2>\n<p>The &#8216;chage&#8217; command, while powerful on its own, can be even more useful when incorporated into larger scripts or projects. Its functionality can be combined with other commands to create more complex and efficient scripts.<\/p>\n<h3>Integrating &#8216;chage&#8217; into Scripts<\/h3>\n<p>For instance, you might want to create a script that sets up new users and configures their password policies. The &#8216;chage&#8217; command can be used in conjunction with the &#8216;useradd&#8217; command to achieve this.<\/p>\n<pre><code class=\"language-bash line-numbers\">#!\/bin\/bash\n\nusername=$1\n\nsudo useradd $username\nsudo chage -M 30 $username\n\n# Output:\n# Adding user `username' ...\n# Adding new group `username' (1001) ...\n# Adding new user `username' (1001) with group `username' ...\n# Creating home directory `\/home\/username' ...\n# Copying files from `\/etc\/skel' ...\n# Changing the aging information for username\n# Password expires: Aug 30, 2022\n<\/code><\/pre>\n<p>This script creates a new user and sets their password to expire after 30 days. The output confirms the successful creation of the user and the change of the password expiry date.<\/p>\n<h3>Related Commands and Functions<\/h3>\n<p>There are several commands and functions that often accompany the &#8216;chage&#8217; command in typical use cases. These include &#8216;useradd&#8217; for adding new users, &#8216;passwd&#8217; for changing passwords, and &#8216;usermod&#8217; for modifying user accounts.<\/p>\n<h2>Further Resources for Mastering Linux Password Management<\/h2>\n<p>To further enhance your understanding and mastery of Linux password management, here are some additional resources:<\/p>\n<ol>\n<li><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/tldp.org\/LDP\/sag\/html\/user-admin.html\" target=\"_blank\" rel=\"noopener\">The Linux Documentation Project&#8217;s Guide on User Administration<\/a>: This guide from The Linux Documentation Project provides comprehensive information on user administration in Linux systems.<\/p>\n<\/li>\n<li>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-add-and-delete-users-on-ubuntu-18-04\" target=\"_blank\" rel=\"noopener\">Digital Ocean&#8217;s Tutorial on How To Manage Users on Ubuntu 18.04<\/a>: This tutorial, provided by Digital Ocean, focuses on managing user accounts specifically on Ubuntu 18.04.<\/p>\n<\/li>\n<li>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/linuxize.com\/post\/how-to-add-and-delete-users-on-centos-8\/\" target=\"_blank\" rel=\"noopener\">Linuxize&#8217;s Guide on How to Add and Delete Users on CentOS 8<\/a>: Linuxize&#8217;s guide specifically targets CentOS 8 users and provides methods for management.<\/p>\n<\/li>\n<\/ol>\n<p>These resources provide in-depth guides and tutorials on Linux user and password management, including the use of commands like &#8216;chage&#8217;.<\/p>\n<h2>Wrapping Up: Mastering the &#8216;chage&#8217; Command in Linux<\/h2>\n<p>In this comprehensive guide, we&#8217;ve delved into the installation and usage of the &#8216;chage&#8217; command in Linux, a vital tool for managing password expiration policies.<\/p>\n<p>We started off by discussing the basic installation of the &#8216;chage&#8217; command using package managers like APT and YUM. We then progressed to more advanced topics, such as installing &#8216;chage&#8217; from source code and installing different versions of &#8216;chage&#8217;. We also explored how to use the &#8216;chage&#8217; command and verify its installation.<\/p>\n<p>We addressed common issues that might arise when using &#8216;chage&#8217;, such as &#8216;command not found&#8217; and &#8216;permission denied&#8217; errors, and provided solutions to these problems. Furthermore, we discussed alternative methods for managing password expiration, including using the &#8216;passwd&#8217; command and manually editing the &#8216;\/etc\/shadow&#8217; file.<\/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>&#8216;chage&#8217; Command<\/td>\n<td>Easy to use, Pre-installed on most Linux distributions<\/td>\n<td>Errors may require troubleshooting<\/td>\n<\/tr>\n<tr>\n<td>&#8216;passwd&#8217; Command<\/td>\n<td>Versatile, Can change password and set expiry date<\/td>\n<td>Less comprehensive than &#8216;chage&#8217;<\/td>\n<\/tr>\n<tr>\n<td>Manual Editing of &#8216;\/etc\/shadow&#8217;<\/td>\n<td>Provides the most control<\/td>\n<td>Risky, can cause serious issues if not done correctly<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Whether you&#8217;re a beginner just starting out with the &#8216;chage&#8217; command or an experienced user looking to deepen your understanding, we hope this guide has been a valuable resource. The &#8216;chage&#8217; command is a powerful tool in the Linux ecosystem, and mastering it can greatly enhance your system administration skills. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you struggling with managing password expiration in your Linux system? You&#8217;re not alone. Many Linux users, especially beginners, find this task a bit daunting. But, the &#8216;chage&#8217; command is here to help. Like a vigilant security guard, it assists you in managing password expiration policies effectively. It&#8217;s also readily available on most package management [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":14750,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[124,3,9],"tags":[],"class_list":["post-6563","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\/6563","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=6563"}],"version-history":[{"count":7,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/6563\/revisions"}],"predecessor-version":[{"id":14963,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/6563\/revisions\/14963"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media\/14750"}],"wp:attachment":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media?parent=6563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/categories?post=6563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/tags?post=6563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}