How to generate crypt encryption password under Linux

Source: Internet
Author: User
Tags crypt lua

This command is used to generate the password in the crypt format:

mkpasswd

After you enter a command, the program asks for a password and then generates a string in crypt format.

If you are using an Apache Web server, you can also use HTPASSWD:

Htpasswd-nd User

It doesn't matter what the user name is, we are concerned with the password. This command will output a string in User:password format, and it will be OK to copy the password field directly.

If you have OpenSSL, you can use the OpenSSL command:

OpenSSL Passwd-crypt MyPassword

Replace the MyPassword in the above command with the password string you want to use.

There are other ways to enter commands directly in the command line, but the problem is that you can see the password in the PS command, and the password will be recorded in the Shell history.

But there is a solution to this problem: using a script, or a language interpreter.

For example, using Perl:

Perl-e "Print crypt (' Password ', ' sa ');"

Perl requires a cryptographic salt, such as the use of SA (salt refers to the random string used in encryption, with different salt to generate different encryption results).

Ruby also needs to encrypt salt:

Ruby-e ' print ' Password ". Crypt (" JU "); Print ("\ n"); '

PHP can also:

Php-r "Print (Crypt (' Password ', ' JU '). \ "\n\"); "

It is important to note that if you do not use a cryptographic salt (such as the Ju in the command above), the output string will not be in the Crypt encryption format, but in the MD5 encrypted format. So, the encryption salt is actually a necessary parameter.

Python needs to import the crypt library and use the encrypted salt:

Python-c ' Import crypt; Print Crypt.crypt ("password", "Fx") '

The crypto salt here is FX.

The database can also generate crypt passwords. For example, with MySQL:

echo "Select Encrypt (' Password ');" | Mysql

In addition, Tcl,ubuntu under the TRF, as well as LUA Lua-crypt plug-ins can also achieve the same purpose.

How to generate crypt encryption password under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.