Shell script: Several possible ways to produce random passwords

Source: Internet
Author: User

1. Generate a random password (urandom version)

#!/bin/bash#author: Tintin (Jacob) #/dev/urandom file is a Linux built-in random device file #cat/dev/urandom can look inside the content, CTRL + C exit View # After viewing the contents of the file, Found content somewhat too random, including many special symbols, we need the password do not want to use these symbols #tr-dc ' _a-za-z0-9 ' </dev/urandom #该命令可以将随机文件中其他的字符删除, keep only uppercase and lowercase letters, numbers, underscores, But it's still too much. # we can continue to pass optimized content through the pipeline to the head command, showing only the first 10 bytes in a large amount of data # Note a preceded by an underscore tr-dc ' _a-za-z0-9 ' </dev/urandom | Head-c 10

2. Generate random password (string interception version)

#!/bin/bash#author: The Adventures of Tintin (Jacob) #设置变量key, all the possibilities of storing passwords (password vault), if additional characters are needed please add other password characters yourself # use $ #统计密码库的长度key = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "num=${#key} #设置初始密码为空pass = ' #循环8次, generate 8 for random password # Each time a random number of the length of the password library to take the remainder, to ensure that the extracted password characters do not exceed the length of the password vault # every time a random password is fetched, and the random password is appended to the pass variable last for i in {1..8}do index=$[random%num] pas s= $pass ${key: $index: 1}doneecho $pass

3. Generate random password (UUID version, 16 binary password)

#!/bin/bashuuidgen

4. generate random password (process ID version, digital password)

#!/bin/bashecho $$


This article is from the "Ding Ding Adventures" blog, please be sure to keep this source http://manual.blog.51cto.com/3300438/1969834

Shell script: Several possible ways to produce random passwords

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.