Reputation: 743
I have a daily bash process that requires using a new password everyday.
To avoid dealing with special characters, I generate passwords using the MD5 of the product of two $RANDOM
variables:
md5sum <<< $(($RANDOM * $RANDOM))
My idea is: since $RANDOM
generates a random integer between 0 and 32,767, then generating two random ints and multiplying them increases the search space to 32,767^2 = 1,071,711,169
I am not a security expert, so I am curious if my approach is reasonably secure, if not, what are better approaches?
Upvotes: 1
Views: 3764
Reputation: 123490
No, this is not reasonably secure. There are several problems:
Upvotes: 3
Reputation: 113864
A secure way to generate a password of any desired length, say 20 characters, and consisting only of alphanumeric characters is:
cat /dev/random | tr -dc '[:alnum:]' | head -c 20
If /dev/random
is too slow for your taste, the following is fast and probably more than good enough:
cat /dev/urandom | tr -dc '[:alnum:]' | head -c 20
This has the advantages over md5sum because (a) it uses all alphabetic characters, not just a-f, and (b) it produces both upper and lower case.
For a discussion of the security and urandom
vs random
, see this post: "When to use /dev/random vs /dev/urandom".
Upvotes: 11