Linux - How to automatically generate random passwords
In this article I'm going to show you how to easily generate random passwords on Linux operating systems. We will also try to prepare bash script which should automatically generate given number of passwords for specified length.
Why should I generate passwords?
Automatically generating passwords can be really useful for creating new user accounts. Because of Linux's virtual devices created for generating random bytes it is quite easy to do that. These devices are: /dev/random and /dev/urandom. The main difference between them is that the /dev/urandom is not restricted by buffer size and it can be used for generating great amount of bytes, but less randomness. So it is accurate for generating temporary passwords.
How to generate passwords?
First of all, let's see what /dev/urandom returns:���f��fFR�#�P��+�<�O���㦙Ei2[H�P
- -i (ignore case distinctions)
- -m <number> (number of matching lines to find)
- -o (return only matching string)
- -a (process a binary file, in this case /dev/urandom, as if it were text)
2yQXU
W7qwQ5IRK9
XsGdCadYrC
WwjEbkILfy
bExdl1VjhM
RYcqkWodT3
How to improve this process?
If we are going to generate passwords often, it will be more comfortable to create bash script which takes two parameters - number of passwords and length of them. Scripts are easier to be used in other scripts or applications. What I propose is:# Mateusz Chmielewski (www.mblog.boo.pl)
# Script takes two parameters:
#1 - number of passwords
#2 - lenght of the password
egrep -aio -m $1 "[a-z0-9]{$2}" /dev/urandom
At the end, please look at this exemplary script execution:
vuzFRIl
cF2Zi31
xE88E9g
AomosM6
DneeVn7
vYpyMB7
b55mlO0
h1kJfAt
RUZAWSJ
qO7mMa9
Komentarze (0) - Nikt jeszcze nie komentował - bądź pierwszy!