mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
[Translated]20150331 How to Generate or Encrypt or Decrypt Random Passwords in Linux.md
This commit is contained in:
parent
a4e3963eab
commit
eaae2abbe8
@ -1,106 +0,0 @@
|
||||
FSSlc translating
|
||||
|
||||
How to Generate/Encrypt/Decrypt Random Passwords in Linux
|
||||
================================================================================
|
||||
We have taken initiative to produce Linux tips and tricks series. If you’ve missed the last article of this series, you may like to visit the link below.
|
||||
|
||||
注:此篇文章做过原文
|
||||
- [5 Interesting Command Line Tips and Tricks in Linux][1]
|
||||
|
||||
In this article, we will share some interesting Linux tips and tricks to generate random passwords and also how to encrypt and decrypt passwords with or without slat method.
|
||||
|
||||
Security is one of the major concern of digital age. We put on password to computers, email, cloud, phone, documents and what not. We all know the basic to choose the password that is easy to remember and hard to guess. What about some sort of machine based password generation automatically? Believe me Linux is very good at this.
|
||||
|
||||
**1. Generate a random unique password of length equal to 10 characters using command ‘pwgen‘. If you have not installed pwgen yet, use Apt or YUM to get.**
|
||||
|
||||
$ pwgen 10 1
|
||||
|
||||
![Generate Random Unique Password](http://www.tecmint.com/wp-content/uploads/2015/03/Generate-Random-Unique-Password-in-Linux.gif)
|
||||
Generate Random Unique Password
|
||||
|
||||
Generate several random unique passwords of character length 50 in one go!
|
||||
|
||||
$ pwgen 50
|
||||
|
||||
![Generate Multiple Random Passwords](http://www.tecmint.com/wp-content/uploads/2015/03/Generate-Multiple-Random-Passwords.gif)
|
||||
Generate Multiple Random Passwords
|
||||
|
||||
**2. You may use ‘makepasswd‘ to generate random, unique password of given length as per choice. Before you can fire makepasswd command, make sure you have installed it. If not! Try installing the package ‘makepasswd’ using Apt or YUM.**
|
||||
|
||||
Generate a random password of character length 10. Default Value is 10.
|
||||
|
||||
$ makepasswd
|
||||
|
||||
![makepasswd Generate Unique Password](http://www.tecmint.com/wp-content/uploads/2015/03/mkpasswd-generate-unique-password.gif)
|
||||
makepasswd Generate Unique Password
|
||||
|
||||
Generate a random password of character length 50.
|
||||
|
||||
$ makepasswd --char 50
|
||||
|
||||
![Generate Length 50 Password](http://www.tecmint.com/wp-content/uploads/2015/03/Random-Password-Generate.gif)
|
||||
Generate Length 50 Password
|
||||
|
||||
Generate 7 random password of 20 characters.
|
||||
|
||||
$ makepasswd --char 20 --count 7
|
||||
|
||||
![](http://www.tecmint.com/wp-content/uploads/2015/03/Generate-20-Character-Password.gif)
|
||||
|
||||
**3. Encrypt a password using crypt along with salt. Provide salt manually as well as automatically.**
|
||||
|
||||
For those who may not be aware of salt,
|
||||
|
||||
Salt is a random data which servers as an additional input to one way function in order to protect password against dictionary attack.
|
||||
|
||||
Make sure you have installed mkpasswd installed before proceeding.
|
||||
|
||||
The below command will encrypt the password with salt. The salt value is taken randomly and automatically. Hence every time you run the below command it will generate different output because it is accepting random value for salt every-time.
|
||||
|
||||
$ mkpasswd tecmint
|
||||
|
||||
![Encrypt Password Using Crypt](http://www.tecmint.com/wp-content/uploads/2015/03/Encrypt-Password-in-Linux.gif)
|
||||
Encrypt Password Using Crypt
|
||||
|
||||
Now lets define the salt. It will output the same result every-time. Note you can input anything of your choice as salt.
|
||||
|
||||
$ mkpasswd tecmint -s tt
|
||||
|
||||
![Encrypt Password Using Salt](http://www.tecmint.com/wp-content/uploads/2015/03/Encrypt-Password-Using-Salt.gif)
|
||||
Encrypt Password Using Salt
|
||||
|
||||
Moreover, mkpasswd is interactive and if you don’t provide password along with the command, it will ask password interactively.
|
||||
|
||||
**4. Encrypt a string say “Tecmint-is-a-Linux-Community” using aes-256-cbc encryption using password say “tecmint” and salt.**
|
||||
|
||||
# echo Tecmint-is-a-Linux-Community | openssl enc -aes-256-cbc -a -salt -pass pass:tecmint
|
||||
|
||||
![Encrypt A String in Linux](http://www.tecmint.com/wp-content/uploads/2015/03/Encrypt-A-String-in-Linux.gif)
|
||||
Encrypt A String in Linux
|
||||
|
||||
Here in the above example the output of 注:此篇原文也做过[echo command][2] is pipelined with openssl command that pass the input to be encrypted using Encoding with Cipher (enc) that uses aes-256-cbc encryption algorithm and finally with salt it is encrypted using password (tecmint).
|
||||
|
||||
**5. Decrypt the above string using openssl command using the -aes-256-cbc decryption.**
|
||||
|
||||
# echo U2FsdGVkX18Zgoc+dfAdpIK58JbcEYFdJBPMINU91DKPeVVrU2k9oXWsgpvpdO/Z | openssl enc -aes-256-cbc -a -d -salt -pass pass:tecmint
|
||||
|
||||
![Decrypt String in Linux](http://www.tecmint.com/wp-content/uploads/2015/03/Decrypt-String-in-Linux.gif)
|
||||
Decrypt String in Linux
|
||||
|
||||
That’s all for now. If you know any such tips and tricks you may send us your tips at admin@tecmint.com, your tip will be published under your name and also we will include it in our future article.
|
||||
|
||||
Keep connected. Keep Connecting. Stay Tuned. Don’t forget to provide us with your valuable feedback in the comments below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/generate-encrypt-decrypt-random-passwords-in-linux/
|
||||
|
||||
作者:[Avishek Kumar][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/avishek/
|
||||
[1]:http://www.tecmint.com/5-linux-command-line-tricks/
|
||||
[2]:http://www.tecmint.com/echo-command-in-linux/
|
@ -0,0 +1,103 @@
|
||||
如何在 Linux 中产生、加密或解密随机密码
|
||||
================================================================================
|
||||
我们一直积极地提供有关 Linux 技巧的系列文章,如果你错过了这个系列的最新文章,你或许可以去访问下面的链接。
|
||||
|
||||
注:此篇文章做过原文
|
||||
- [Linux 中 5 个有趣的命令行技巧][1] (注:这篇文章还没有被翻译,在 20150316 选的题)
|
||||
|
||||
在这篇文章中,我们将分享一些有趣 Linux 技巧,内容是有关如何产生随机密码以及加密或解密这些经过加盐或没有加盐处理的密码。
|
||||
|
||||
安全是数字时代中的一个主要话题。在电脑,email,云端,手机,文档和其他的场合中,我们都会使用到密码。众所周知,选择密码的基本原则是 “易记,难猜”。考虑过使用基于机器自动生成的密码吗?相信我,Linux 非常擅长这方面的工作。
|
||||
|
||||
**1. 使用命令 `pwgen` 来生成一个长度为 10 个字符的唯一的随机密码。假如你还没有安装 pwgen,请使用 Apt 或 YUM 等包管理器来安装它。**
|
||||
|
||||
$ pwgen 10 1
|
||||
|
||||
![生成一个唯一的随机密码](http://www.tecmint.com/wp-content/uploads/2015/03/Generate-Random-Unique-Password-in-Linux.gif)
|
||||
生成一个唯一的随机密码
|
||||
|
||||
一口气生成若干组长度为 50 个字符的唯一的随机密码!
|
||||
|
||||
$ pwgen 50
|
||||
|
||||
![生成多组随机密码](http://www.tecmint.com/wp-content/uploads/2015/03/Generate-Multiple-Random-Passwords.gif)
|
||||
生成多组随机密码
|
||||
|
||||
**2. 你还可以使用 `makepasswd` 来每次生成一个给定长度的唯一的随机密码。在你把玩 makepasswd 命令之前,请确保你已经安装了它。如若没有安装它,试试使用 Apt 或 YUM 包管理器来安装 `makepasswd`这个软件包。**
|
||||
|
||||
生成一个长度为 10 个字符的随机密码。该命令产生的密码的长度默认为 10。
|
||||
|
||||
$ makepasswd
|
||||
|
||||
![使用 makepasswd 生成唯一的密码](http://www.tecmint.com/wp-content/uploads/2015/03/mkpasswd-generate-unique-password.gif)
|
||||
使用 makepasswd 生成唯一的密码
|
||||
|
||||
生成一个长度为 50 个字符的随机密码。
|
||||
|
||||
$ makepasswd --char 50
|
||||
|
||||
![生成长度为 50 的密码](http://www.tecmint.com/wp-content/uploads/2015/03/Random-Password-Generate.gif)
|
||||
生成长度为 50 的密码
|
||||
|
||||
生成 7 个长度为 20 个字符的随机密码。
|
||||
|
||||
$ makepasswd --char 20 --count 7
|
||||
|
||||
![](http://www.tecmint.com/wp-content/uploads/2015/03/Generate-20-Character-Password.gif)
|
||||
|
||||
**3. 使用带“盐”的 Crypt(注:这里应该指的是一个函数,可以参考[这里](http://man7.org/linux/man-pages/man3/crypt.3.html) ) 来加密一个密码。提供手动或自动添加 “盐”。**
|
||||
|
||||
对于那些不清楚 **盐** 的意义的人,
|
||||
|
||||
这里的 “盐” 指的是一个随机数据,它作为密码生成函数的一个额外的输入, 目的是保护密码免受词典攻击。
|
||||
|
||||
在执行下面的操作前,请确保你已经安装了 `mkpasswd`。
|
||||
|
||||
下面的命令将带 “盐” 加密一个密码。“盐” 的值是随机自动生成的。所以每次你运行下面的命令时,都将产生不同的输出,因为它每次接受了随机取值的 “盐”。
|
||||
|
||||
$ mkpasswd tecmint
|
||||
|
||||
![使用 Crypt 来加密密码](http://www.tecmint.com/wp-content/uploads/2015/03/Encrypt-Password-in-Linux.gif)
|
||||
使用 Crypt 来加密密码
|
||||
|
||||
现在让我们来手动定义 “盐” 的值。每次它将产生相同的结果。请注意你可以输入任何你想输入的值来作为 “盐” 的值。
|
||||
|
||||
$ mkpasswd tecmint -s tt
|
||||
|
||||
![带“盐”加密密码](http://www.tecmint.com/wp-content/uploads/2015/03/Encrypt-Password-Using-Salt.gif)
|
||||
带“盐”加密密码
|
||||
|
||||
另外, mkpasswd 还是交互式的,假如你在命令中没有提供密码,它将主动询问你来输入密码。
|
||||
|
||||
**4. 使用 aes-256-cbc 加密算法并使用密码(如 “tecmint”) 并带“盐” 加密一个字符串(如 “Tecmint-is-a-Linux-Community”)。**
|
||||
|
||||
# echo Tecmint-is-a-Linux-Community | openssl enc -aes-256-cbc -a -salt -pass pass:tecmint
|
||||
|
||||
![在 Linux 中加密一个字符串](http://www.tecmint.com/wp-content/uploads/2015/03/Encrypt-A-String-in-Linux.gif)
|
||||
在 Linux 中加密一个字符串
|
||||
|
||||
在上面例子中, [echo 命令][2](注:此篇原文也做过,这里是链接 http://linux.cn/article-3948-1.html) 的输出通过管道传递给了 openssl 命令,使得该输出被 Cipher(enc) 所加密,这个过程中使用了 aes-256-cbc 加密算法,并附带了密码 (tecmint) 和 “盐” 。
|
||||
|
||||
**5. 使用 openssl 命令的 -aes-256-cbc 解密选项来解密上面的字符串。**
|
||||
|
||||
# echo U2FsdGVkX18Zgoc+dfAdpIK58JbcEYFdJBPMINU91DKPeVVrU2k9oXWsgpvpdO/Z | openssl enc -aes-256-cbc -a -d -salt -pass pass:tecmint
|
||||
|
||||
![在 Linux 中解密字符串](http://www.tecmint.com/wp-content/uploads/2015/03/Decrypt-String-in-Linux.gif)
|
||||
在 Linux 中解密字符串
|
||||
|
||||
现在就是这些内容了。假如你知道任何这类的技巧,请将你的技巧发送到 admin@tecmint.com 邮箱中,你的技巧将会以你的名义来发表,同时我们也将在我们将来的文章中把它包含进去。
|
||||
|
||||
保持联系,保持连接,敬请关注。不要忘了在下面的评论中提供给我们您有价值的反馈。
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/generate-encrypt-decrypt-random-passwords-in-linux/
|
||||
|
||||
作者:[Avishek Kumar][a]
|
||||
译者:[FSSlc](https://github.com/FSSlc)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/avishek/
|
||||
[1]:http://www.tecmint.com/5-linux-command-line-tricks/
|
||||
[2]:http://www.tecmint.com/echo-command-in-linux/
|
Loading…
Reference in New Issue
Block a user