The function and installation of HTPASSWD
HTPASSWD is a tool for Apache, which is primarily used to create and update text files that store user names and passwords, primarily for authentication based on HTTP users.
The installation of htpasswd is simple, and it is generated with the installation of Apache. This is the same as the AB tool, and here's not a detailed description.
If Apache is installed via RPM's yum, the command is stored in the/usr/bin/directory as follows:
Which htpasswd
/usr/bin/htpasswd
If Apache is installed in source mode, the command is stored in the bin directory of the Apache installation directory, as follows:
/usr/local/apache2/bin
HTPASSWD command usage, we can view it through the help of HTPASSWD, as follows:
Htpasswd-h
Second, htpasswd order detailed
In the first section, we looked at the help for htpasswd. Now let's explain the relevant parameters in the Help information.
HTPASSWD's help information is as follows:
Htpasswd-h
htpasswd [-CMDPSD] passwordfile username
HTPASSWD-B[CMDPSD] passwordfile username password
Htpasswd-n[mdps] Username
HTPASSWD-NB[MDPS] Username password
HTPASSWD command option parameter description:
-C creates an encrypted file.
-N does not update the encrypted file, only the user name and password that are encrypted by the HTPASSWD command are displayed on the screen.
The-M default htpassswd command encrypts the password using the MD5 algorithm, which is not available by default.
-D indicates that the HTPASSSWD command uses the crypt algorithm to encrypt the password.
-S indicates that the HTPASSSWD command uses the SHA algorithm to encrypt the password.
-P indicates that the HTPASSSWD command does not encrypt the password, that is, the plaintext password.
-B indicates that the user name and password are entered together on the HTPASSSWD command line instead of the password as prompted.
-D indicates that the specified user is deleted.
Iii. Examples of htpasswd
In the second step, we list the parameter descriptions for HTPASSWD, and now we'll show you how to use these parameters with examples.
3.1 Adding users using the HTPASSWD command
With the HTPASSWD command to add a user, we can use the-B and-C parameters. As follows:
HTPASSWD-BC ilannifile Ilanniuser 123456
Cat Ilannifile
HTPASSWD-BC ilannifile Ilanniuser 123456
Indicates that a ilannifile password file is generated in the current directory, and a user named Ilanniuser password 123456 is added, which is encrypted by default MD5 encryption.
3.2 New users in the original password file
A new user in the original password file, we can use the-b parameter. As follows:
Htpasswd-b ilannifile ilannitwo 123456
Cat Ilannifile
Htpasswd-b ilannifile ilannitwo 123456
Indicates that a user named Ilannitwo with a password of 123456 is added to the ilannifile password file.
Note: the-c parameter must not be added at this time, or it will overwrite the original password file and create a new password file.
3.3 Do not update the password file, only display the encrypted username and password
Instead of updating the password file and displaying only the encrypted username and password, we can use the-n argument. As follows:
Htpasswd-n Ilannitwo
Note the-n parameter must be followed by the user already in the password file. To tell you the truth, this argument has little practical significance.
3.4 Using the htpasswd command to delete a username and password
To remove a user who already exists in the password file, we can do so by using the-D argument. As follows:
htpasswd-d Ilannifile Ilannitwo
3.5 using the HTPASSWD command to modify the user password
To achieve this goal, we need to use the htpasswd command to delete the specified user, and then use HTPASSWD to create users to implement the ability to modify the password. As follows:
Iv. Application of HTPASSWD
The
htpasswd can be integrated with Nagios, SVN, Nginx, Apache and so on. We will introduce htpasswd with the integration of the above several programs separately.