Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate, encrypt and decrypt random passwords in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to generate and encrypt and decrypt random passwords in Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Use the command pwgen to generate a unique random password of 10 characters in length. If you have not already installed pwgen, please use a package manager such as Apt or YUM to install it.

The code is as follows:

$pwgen 10 1

Generate a unique random password

Generate several unique random passwords with a length of 50 characters in one breath!

The code is as follows:

$pwgen 50

Generate multiple random passwords

two。 You can also use makepasswd to generate a unique random password of a given length at a time. Before you play with the makepasswd command, make sure you have it installed. If you don't have it installed, try using Apt or the YUM package manager to install the makepasswd package.

Generate a random password of 10 characters in length. The length of the password generated by this command defaults to 10.

The code is as follows:

$makepasswd

Use makepasswd to generate unique passwords

Generate a random password of 50 characters in length.

The code is as follows:

$makepasswd-- char 50

Generate a password of length 50

Generate 7 random passwords with a length of 20 characters.

The code is as follows:

$makepasswd-char 20-count 7

3. Use Crypt with "salt" to encrypt a password. Provide manual or automatic add "salt".

For those who don't know the meaning of salt, the "salt" here refers to a random data that serves as an additional input to the password generation function to protect the password from dictionary attacks.

Make sure that you have installed mkpasswd before performing the following actions.

The following command encrypts a password with "salt". The value of "salt" is randomly generated automatically. So each time you run the following command, it will produce a different output because it accepts a random value of "salt" each time.

The code is as follows:

$mkpasswd tecmint

Use Crypt to encrypt passwords

Now let's manually define the value of "salt". It will produce the same result every time. Please note that you can enter any value you want as the value of "salt".

The code is as follows:

$mkpasswd tecmint-s tt

Encrypted password with "salt"

In addition, mkpasswd is interactive, and if you do not provide a password in the command, it will actively ask you to enter the password.

4. Use the aes-256-cbc encryption algorithm and encrypt a string (such as "Tecmint-is-a-Linux-Community") with a password with "salt" (such as "tecmint").

The code is as follows:

# echo Tecmint-is-a-Linux-Community | openssl enc-aes-256-cbc-a-salt-pass pass:tecmint

Encrypt a string in Linux

In the above example, the output of the echo command is piped to the openssl command so that it is encrypted by encryption encoding (enc:Encoding with Cipher), using the aes-256-cbc encryption algorithm with a password (tecmint) and "salt".

5. Use the-aes-256-cbc decryption option of the openssl command to decrypt the above string.

The code is as follows:

# echo U2FsdGVkX18Zgoc+dfAdpIK58JbcEYFdJBPMINU91DKPeVVrU2k9oXWsgpvpdO/Z | openssl enc-aes-256-cbc-a-d-salt-pass pass:tecmint

Decrypt a string in Linux

This is the end of the content of "how to generate and encrypt random passwords in Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report