Generating a pseudorandom password or string in Linux bash

Revision history
Tags: linux bash

Define a function in e.g. ~/.bashrc

genpasswd() {
  tr -dc A-Za-z0-9 < /dev/urandom | head -c ${1:-36} | xargs

Where 36 is default length if no parameter is given


$ genpasswd

$ genpasswd 7


If you have any comments or feedback, please send me an e-mail. (stig at stigok dotcom).

Did you find any typos, incorrect information, or have something to add? Then please propose a change to this post.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.