Simple one-liner to generate secure passwords in linux

I recently checked my firefox-account and my logins and passwords.

Bad idea…

I noticed that i use pretty weak passwords in general, but i dont want to use a password-manager (anymore).

So… i wrote a simple line to get me random characters from /dev/random and put it into my .bashrc.

Here it is:

echo \ && head -c 100 /dev/urandom | tr -cd '[:alnum:]' | head -c 18 && echo \ && echo \ 

The echos at the beginning and end are for line-breaks to make the output more distinguishable from the rest in the terminal. head gives you the first (in this case) 100 characters from /dev/random, tr filters them, and the next head gives you a nice alphanumerical password of the length 18. its unlikely to not get at least 18 alphanum characters out of 100 random ones, so it works. you can tweak the length yourself, but remember to make the input (100) longer if you change your output-length!

After that i put it into my .bashrc to be able to run it from my terminal anytime. An easy way to do that is:

echo "alias passgen='echo \ && head -c 100 /dev/urandom | tr -cd '[:alnum:]' | head -c 18 && echo \ && echo \ '" >> .bashrc

Now i am able to just type “passgen” into my terminal and i get 18 random characters for me to use!

Quite nice.

Leave a Reply

Your email address will not be published.