linux random string/password generator


I had a pretty interesting tease tease – I had to create a huge number of randomly generated passwords as I was required to be of a certain length to contain large lowercase letters and numbers, normal things. Sounds easy, doesn't it?. I used /dev/urandom for the main generation and then with a short pipeline I filtered to the desired number of characters and types of characters to be used. As long as I'm screwed into the main script is the pipeline :

cat /dev/urandom | tr -dc '[:alnum:]' | fold -w 20| head -n 1

So let's take a closer look at what's going on here. We take the output of cat / dev / urandom. Then we filter it to show only small ones, capital letters and numbers. Then with fold we limit the length of the strings to the desired number. Finally, we limit the display only 1 row of the entire output. Basically easy as 1-2-3. If you want to increase the complexity of the password and with special characters in the regular expression of tr can be used :graph: or :print: instead :scooping:, which include all characters without or with space.

cat /dev/urandom | tr -dc '[:graph:]' | fold -w 20 | head -n 1
Enhanced by Zemanta

Leave a Reply

Your email address will not be published.

Anti SPAM *