The method of generating crypt encryption password under Linux

Source: Internet
Author: User
Tags command line crypt lua openssl

We can use the MKPASSWD command: This command is used to generate the password in the crypt format:

mkpasswd

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

If you use the Apache Web server, you can also use HTPASSWD:

Htpasswd-nd User

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

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

OpenSSL Passwd-crypt MyPassword

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

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

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

Like using Perl:

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

Perl requires an encrypted salt, such as a random string used in the use of SA (salt), which can generate different cryptographic results with different salts.

Ruby also needs to encrypt the salt:

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

PHP can also:

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

It should be noted that if you do not use encrypted salts (such as the Ju in the above command), the output string will not be crypt encrypted, but MD5 in encrypted format. So, the encrypted salt is actually a necessary parameter.

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

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

The encrypted salt here is FX.

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

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

In addition, the TRF in Tcl,ubuntu, and the LUA Lua-crypt Plug-ins can achieve the same goal.

Welcome to add other ways!

Related Article

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.