Generating a pseudorandom password or string in Linux bash
- 26 Feb 2017: Post was created (diff)
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
Usage
$ genpasswd
GVQ3ZHqrBRDzB1QwASA9uk6YsZPto2GWeRWR
$ genpasswd 7
qvPWx7N
References
- http://www.shellhacks.com/en/Generating-Random-Passwords-in-the-Linux-Command-Line

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.