You can use the following command to generate the random password:
$ tr -dc A-Za-z0-9 < /dev/urandom | head -c 8 | xargs
Sample output:
4fFUND1d
You can create a bash shell function as follows (add to your ~/.bashrc):
# Random password generator genpasswd() { tr -dc A-Za-z0-9 < /dev/urandom | head -c ${1:-8} | xargs }
Reload .bashrc file.
$ . ~/.bashrc
Now use genpasswd to generate random passwords:
$ genpasswd vmuWt7TS $ genpasswd 10 ymkIgxcdCh $ genpasswd 16 wQnqgdc5tAQoiBdf
Is it possible to add symbol to the genpasswd function ?
Yes hedy, you can. Kindly catch below one command and understand it accordingly.
cat /dev/urandom | tr -dc ‘[a-z][A-Z][0-9]-_!@#$%^&*()_+{}|:?=’ | fold -w 12 | head -n 5