自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

八種幫你在Linux上生成隨機(jī)密碼的方法

系統(tǒng) Linux
在這篇文章中,我們將引導(dǎo)你通過(guò)幾種不同的方式在 Linux 終端中生成隨機(jī)密碼。其中幾種利用原生 Linux 命令,另外幾種則利用極易在 Linux 機(jī)器上安裝的第三方工具或?qū)嵱贸绦驅(qū)崿F(xiàn)。

 https://s5.51cto.com/oss/201802/07/0216c08682255123b4accc2c1763474f.png

學(xué)習(xí)使用 8 種 Linux 原生命令或第三方實(shí)用程序來(lái)生成隨機(jī)密碼。

在這篇文章中,我們將引導(dǎo)你通過(guò)幾種不同的方式在 Linux 終端中生成隨機(jī)密碼。其中幾種利用原生 Linux 命令,另外幾種則利用極易在 Linux 機(jī)器上安裝的第三方工具或?qū)嵱贸绦驅(qū)崿F(xiàn)。在這里我們利用像 openssl, dd, md5sum, tr, urandom 這樣的原生命令和 mkpasswd,randpw,pwgen,spw,gpg,xkcdpass,diceware,revelation,keepaasx,passwordmaker 這樣的第三方工具。

其實(shí)這些方法就是生成一些能被用作密碼的隨機(jī)字母字符串。隨機(jī)密碼可以用于新用戶(hù)的密碼,不管用戶(hù)基數(shù)有多大,這些密碼都是***的。話(huà)不多說(shuō),讓我們來(lái)看看 8 種不同的在 Linux 上生成隨機(jī)密碼的方法吧。

使用 mkpasswd 實(shí)用程序生成密碼

mkpasswd 在基于 RHEL 的系統(tǒng)上隨 expect 軟件包一起安裝。在基于 Debian 的系統(tǒng)上 mkpasswd 則在軟件包 whois 中。直接安裝 mkpasswd 軟件包將會(huì)導(dǎo)致錯(cuò)誤:

  • RHEL 系統(tǒng):軟件包 mkpasswd 不可用。
  • Debian 系統(tǒng):錯(cuò)誤:無(wú)法定位軟件包 mkpasswd。

所以按照上面所述安裝他們的父軟件包,就沒(méi)問(wèn)題了。

運(yùn)行 mkpasswd 來(lái)獲得密碼

  1. root@kerneltalks# mkpasswd << on RHEL
  2. zt*hGW65c
  3.  
  4. root@kerneltalks# mkpasswd teststring << on Ubuntu
  5. XnlrKxYOJ3vik

這個(gè)命令在不同的系統(tǒng)上表現(xiàn)得不一樣,所以工作方式各異。你也可以通過(guò)參數(shù)來(lái)控制長(zhǎng)度等選項(xiàng),可以查閱 man 手冊(cè)來(lái)探索。

使用 openssl 生成密碼

幾乎所有 Linux 發(fā)行版都包含 openssl。我們可以利用它的隨機(jī)功能來(lái)生成可以用作密碼的隨機(jī)字母字符串。

  1. root@kerneltalks # openssl rand -base64 10
  2. nU9LlHO5nsuUvw==

這里我們使用 base64 編碼隨機(jī)函數(shù),***一個(gè)數(shù)字參數(shù)表示長(zhǎng)度。

使用 urandom 生成密碼

設(shè)備文件 /dev/urandom 是另一個(gè)獲得隨機(jī)字符串的方法。我們使用 tr 功能并裁剪輸出來(lái)獲得隨機(jī)字符串,并把它作為密碼。

  1. root@kerneltalks # strings /dev/urandom |tr -dc A-Za-z0-9 | head -c20; echo
  2. UiXtr0NAOSIkqtjK4c0X

使用 dd 命令生成密碼

我們甚至可以使用 /dev/urandom 設(shè)備配合 dd 命令 來(lái)獲取隨機(jī)字符串。

  1. root@kerneltalks# dd if=/dev/urandom bs=1 count=15|base64 -w 0
  2. 15+0 records in
  3. 15+0 records out
  4. 15 bytes (15 B) copied, 5.5484e-05 s, 270 kB/s
  5. QMsbe2XbrqAc2NmXp8D0

我們需要將結(jié)果通過(guò) base64 編碼使它能被人類(lèi)可讀。你可以使用數(shù)值來(lái)獲取想要的長(zhǎng)度。想要獲得更簡(jiǎn)潔的輸出的話(huà),可以將“標(biāo)準(zhǔn)錯(cuò)誤輸出”重定向到 /dev/null。簡(jiǎn)潔輸出的命令是:

  1. root@kerneltalks # dd if=/dev/urandom bs=1 count=15 2>/dev/null|base64 -w 0
  2. F8c3a4joS+a3BdPN9C++

使用 md5sum 生成密碼

另一種獲取可用作密碼的隨機(jī)字符串的方法是計(jì)算 MD5 校驗(yàn)值!校驗(yàn)值看起來(lái)確實(shí)像是隨機(jī)字符串組合在一起,我們可以用作密碼。確保你的計(jì)算源是個(gè)變量,這樣的話(huà)每次運(yùn)行命令時(shí)生成的校驗(yàn)值都不一樣。比如 datedate 命令 總會(huì)生成不同的輸出。

  1. root@kerneltalks # date |md5sum
  2. 4d8ce5c42073c7e9ca4aeffd3d157102 -

在這里我們將 date 命令的輸出通過(guò) md5sum 得到了校驗(yàn)和!你也可以用 cut 命令 裁剪你需要的長(zhǎng)度。

使用 pwgen 生成密碼

pwgen 軟件包在類(lèi)似 EPEL 軟件倉(cāng)庫(kù)(LCTT 譯注:企業(yè)版 Linux 附加軟件包)中。pwgen 更專(zhuān)注于生成可發(fā)音的密碼,但它們不在英語(yǔ)詞典中,也不是純英文的。標(biāo)準(zhǔn)發(fā)行版?zhèn)}庫(kù)中可能并不包含這個(gè)工具。安裝這個(gè)軟件包然后運(yùn)行 pwgen 命令行。Boom !

  1. root@kerneltalks # pwgen
  2. thu8Iox7 ahDeeQu8 Eexoh0ai oD8oozie ooPaeD9t meeNeiW2 Eip6ieph Ooh1tiet
  3. cootad7O Gohci0vo wah9Thoh Ohh3Ziur Ao1thoma ojoo6aeW Oochai4v ialaiLo5
  4. aic2OaDa iexieQu8 Aesoh4Ie Eixou9ph ShiKoh0i uThohth7 taaN3fuu Iege0aeZ
  5. cah3zaiW Eephei0m AhTh8guo xah1Shoo uh8Iengo aifeev4E zoo4ohHa fieDei6c
  6. aorieP7k ahna9AKe uveeX7Hi Ohji5pho AigheV7u Akee9fae aeWeiW4a tiex8Oht

你的終端會(huì)呈現(xiàn)出一個(gè)密碼列表!你還想要什么呢?好吧。你還想再仔細(xì)探索的話(huà), pwgen 還有很多自定義選項(xiàng),這些都可以在 man 手冊(cè)里查閱到。

使用 gpg 工具生成密碼

GPG 是一個(gè)遵循 OpenPGP 標(biāo)準(zhǔn)的加密及簽名工具。大部分 gpg 工具都預(yù)先被安裝好了(至少在我的 RHEL7 上是這樣)。但如果沒(méi)有的話(huà)你可以尋找 gpggpg2 軟件包并安裝它。

使用下面的命令以從 gpg 工具生成密碼。

  1. root@kerneltalks # gpg --gen-random --armor 1 12
  2. mL8i+PKZ3IuN6a7a

這里我們傳了生成隨機(jī)字節(jié)序列選項(xiàng)(--gen-random),質(zhì)量為 1(***個(gè)參數(shù)),次數(shù) 12 (第二個(gè)參數(shù))。選項(xiàng) --armor 保證以 base64 編碼輸出。

使用 xkcdpass 生成密碼

著名的極客幽默網(wǎng)站 xkcd,發(fā)表了一篇非常有趣的文章,是關(guān)于好記但又復(fù)雜的密碼的。你可以在這里閱讀。所以 xkcdpass 工具就受這篇文章啟發(fā),做了這樣的工作!這是一個(gè) Python 軟件包,可以在這里的 Python 的官網(wǎng)上找到它。

所有的安裝使用說(shuō)明都在上面那個(gè)頁(yè)面提及了。這里是安裝步驟和我的測(cè)試 RHEL 服務(wù)器的輸出,以供參考。

  1. root@kerneltalks # wget https://pypi.python.org/packages/b4/d7/3253bd2964390e034cf0bba227db96d94de361454530dc056d8c1c096abc/xkcdpass-1.14.3.tar.gz#md5=5f15d52f1d36207b07391f7a25c7965f
  2. --2018-01-23 19:09:17-- https://pypi.python.org/packages/b4/d7/3253bd2964390e034cf0bba227db96d94de361454530dc056d8c1c096abc/xkcdpass-1.14.3.tar.gz
  3. Resolving pypi.python.org (pypi.python.org)... 151.101.32.223, 2a04:4e42:8::223
  4. Connecting to pypi.python.org (pypi.python.org)|151.101.32.223|:443... connected.
  5. HTTP request sent, awaiting response... 200 OK
  6. Length: 871848 (851K) [binary/octet-stream]
  7. Saving to: xkcdpass-1.14.3.tar.gz
  8.  
  9. 100%[==============================================================================================================================>] 871,848 --.-K/s in 0.01s
  10.  
  11. 2018-01-23 19:09:17 (63.9 MB/s) - xkcdpass-1.14.3.tar.gz saved [871848/871848]
  12.  
  13.  
  14. root@kerneltalks # tar -xvf xkcdpass-1.14.3.tar.gz
  15. xkcdpass-1.14.3/
  16. xkcdpass-1.14.3/examples/
  17. xkcdpass-1.14.3/examples/example_import.py
  18. xkcdpass-1.14.3/examples/example_json.py
  19. xkcdpass-1.14.3/examples/example_postprocess.py
  20. xkcdpass-1.14.3/LICENSE.BSD
  21. xkcdpass-1.14.3/MANIFEST.in
  22. xkcdpass-1.14.3/PKG-INFO
  23. xkcdpass-1.14.3/README.rst
  24. xkcdpass-1.14.3/setup.cfg
  25. xkcdpass-1.14.3/setup.py
  26. xkcdpass-1.14.3/tests/
  27. xkcdpass-1.14.3/tests/test_list.txt
  28. xkcdpass-1.14.3/tests/test_xkcdpass.py
  29. xkcdpass-1.14.3/tests/__init__.py
  30. xkcdpass-1.14.3/xkcdpass/
  31. xkcdpass-1.14.3/xkcdpass/static/
  32. xkcdpass-1.14.3/xkcdpass/static/eff-long
  33. xkcdpass-1.14.3/xkcdpass/static/eff-short
  34. xkcdpass-1.14.3/xkcdpass/static/eff-special
  35. xkcdpass-1.14.3/xkcdpass/static/fin-kotus
  36. xkcdpass-1.14.3/xkcdpass/static/ita-wiki
  37. xkcdpass-1.14.3/xkcdpass/static/legacy
  38. xkcdpass-1.14.3/xkcdpass/static/spa-mich
  39. xkcdpass-1.14.3/xkcdpass/xkcd_password.py
  40. xkcdpass-1.14.3/xkcdpass/__init__.py
  41. xkcdpass-1.14.3/xkcdpass.1
  42. xkcdpass-1.14.3/xkcdpass.egg-info/
  43. xkcdpass-1.14.3/xkcdpass.egg-info/dependency_links.txt
  44. xkcdpass-1.14.3/xkcdpass.egg-info/entry_points.txt
  45. xkcdpass-1.14.3/xkcdpass.egg-info/not-zip-safe
  46. xkcdpass-1.14.3/xkcdpass.egg-info/PKG-INFO
  47. xkcdpass-1.14.3/xkcdpass.egg-info/SOURCES.txt
  48. xkcdpass-1.14.3/xkcdpass.egg-info/top_level.txt
  49.  
  50.  
  51. root@kerneltalks # cd xkcdpass-1.14.3
  52.  
  53. root@kerneltalks # python setup.py install
  54. running install
  55. running bdist_egg
  56. running egg_info
  57. writing xkcdpass.egg-info/PKG-INFO
  58. writing top-level names to xkcdpass.egg-info/top_level.txt
  59. writing dependency_links to xkcdpass.egg-info/dependency_links.txt
  60. writing entry points to xkcdpass.egg-info/entry_points.txt
  61. reading manifest file 'xkcdpass.egg-info/SOURCES.txt'
  62. reading manifest template 'MANIFEST.in'
  63. writing manifest file 'xkcdpass.egg-info/SOURCES.txt'
  64. installing library code to build/bdist.linux-x86_64/egg
  65. running install_lib
  66. running build_py
  67. creating build
  68. creating build/lib
  69. creating build/lib/xkcdpass
  70. copying xkcdpass/xkcd_password.py -> build/lib/xkcdpass
  71. copying xkcdpass/__init__.py -> build/lib/xkcdpass
  72. creating build/lib/xkcdpass/static
  73. copying xkcdpass/static/eff-long -> build/lib/xkcdpass/static
  74. copying xkcdpass/static/eff-short -> build/lib/xkcdpass/static
  75. copying xkcdpass/static/eff-special -> build/lib/xkcdpass/static
  76. copying xkcdpass/static/fin-kotus -> build/lib/xkcdpass/static
  77. copying xkcdpass/static/ita-wiki -> build/lib/xkcdpass/static
  78. copying xkcdpass/static/legacy -> build/lib/xkcdpass/static
  79. copying xkcdpass/static/spa-mich -> build/lib/xkcdpass/static
  80. creating build/bdist.linux-x86_64
  81. creating build/bdist.linux-x86_64/egg
  82. creating build/bdist.linux-x86_64/egg/xkcdpass
  83. copying build/lib/xkcdpass/xkcd_password.py -> build/bdist.linux-x86_64/egg/xkcdpass
  84. copying build/lib/xkcdpass/__init__.py -> build/bdist.linux-x86_64/egg/xkcdpass
  85. creating build/bdist.linux-x86_64/egg/xkcdpass/static
  86. copying build/lib/xkcdpass/static/eff-long -> build/bdist.linux-x86_64/egg/xkcdpass/static
  87. copying build/lib/xkcdpass/static/eff-short -> build/bdist.linux-x86_64/egg/xkcdpass/static
  88. copying build/lib/xkcdpass/static/eff-special -> build/bdist.linux-x86_64/egg/xkcdpass/static
  89. copying build/lib/xkcdpass/static/fin-kotus -> build/bdist.linux-x86_64/egg/xkcdpass/static
  90. copying build/lib/xkcdpass/static/ita-wiki -> build/bdist.linux-x86_64/egg/xkcdpass/static
  91. copying build/lib/xkcdpass/static/legacy -> build/bdist.linux-x86_64/egg/xkcdpass/static
  92. copying build/lib/xkcdpass/static/spa-mich -> build/bdist.linux-x86_64/egg/xkcdpass/static
  93. byte-compiling build/bdist.linux-x86_64/egg/xkcdpass/xkcd_password.py to xkcd_password.pyc
  94. byte-compiling build/bdist.linux-x86_64/egg/xkcdpass/__init__.py to __init__.pyc
  95. creating build/bdist.linux-x86_64/egg/EGG-INFO
  96. copying xkcdpass.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
  97. copying xkcdpass.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  98. copying xkcdpass.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  99. copying xkcdpass.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  100. copying xkcdpass.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
  101. copying xkcdpass.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  102. creating dist
  103. creating 'dist/xkcdpass-1.14.3-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
  104. removing 'build/bdist.linux-x86_64/egg' (and everything under it)
  105. Processing xkcdpass-1.14.3-py2.7.egg
  106. creating /usr/lib/python2.7/site-packages/xkcdpass-1.14.3-py2.7.egg
  107. Extracting xkcdpass-1.14.3-py2.7.egg to /usr/lib/python2.7/site-packages
  108. Adding xkcdpass 1.14.3 to easy-install.pth file
  109. Installing xkcdpass script to /usr/bin
  110.  
  111. Installed /usr/lib/python2.7/site-packages/xkcdpass-1.14.3-py2.7.egg
  112. Processing dependencies for xkcdpass==1.14.3
  113. Finished processing dependencies for xkcdpass==1.14.3

現(xiàn)在運(yùn)行 xkcdpass 命令,將會(huì)隨機(jī)給出你幾個(gè)像下面這樣的字典單詞:

  1. root@kerneltalks # xkcdpass
  2. broadside unpadded osmosis statistic cosmetics lugged

你可以用這些單詞作為其他命令,比如 md5sum 的輸入,來(lái)獲取隨機(jī)密碼(就像下面這樣),甚至你也可以用每個(gè)單詞的第 N 個(gè)字母來(lái)生成你的密碼!

  1. root@kerneltalks # xkcdpass |md5sum
  2. 45f2ec9b3ca980c7afbd100268c74819 -
  3.  
  4. root@kerneltalks # xkcdpass |md5sum
  5. ad79546e8350744845c001d8836f2ff2 -

或者你甚至可以把所有單詞串在一起作為一個(gè)超長(zhǎng)的密碼,不僅非常好記,也不容易被電腦程序攻破。

 

Linux 上還有像 Diceware、 KeePassX、 RevelationPasswordMaker 這樣的工具,也可以考慮用來(lái)生成強(qiáng)隨機(jī)密碼。

責(zé)任編輯:龐桂玉 來(lái)源: Linux中國(guó)
相關(guān)推薦

2014-08-21 15:26:22

2014-03-27 14:53:33

隨機(jī)密碼

2014-03-04 10:47:52

Linux命令行隨機(jī)密碼

2017-02-08 12:00:45

PHP性能對(duì)比

2015-05-04 14:50:48

PHPPHP生成隨機(jī)密碼

2019-03-27 11:30:30

Linux終端密碼生成器

2009-07-31 09:00:44

ASP.NET生成隨機(jī)

2011-02-25 14:14:32

Linux隨機(jī)密碼

2015-03-26 11:51:22

2022-12-28 15:10:39

LinuxNginx服務(wù)器

2022-10-17 18:29:55

2022-07-06 08:33:15

服務(wù)器安全SSH

2011-05-19 11:30:00

密碼密碼生成器

2022-05-22 13:59:27

Go編程語(yǔ)言

2019-10-16 00:53:56

物聯(lián)網(wǎng)設(shè)備數(shù)據(jù)安全物聯(lián)網(wǎng)安全

2022-08-19 11:17:09

Linux

2020-06-07 11:46:05

密碼信息泄露高強(qiáng)度密碼

2019-07-02 13:16:05

密碼賬號(hào)安全數(shù)據(jù)安全

2023-05-04 18:45:11

2023-06-29 15:10:48

Web開(kāi)發(fā)CSS
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)