openssl rand -base64 32
LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | head -c32; echo ''
32 is length of the generated password.
I recommend the latter because the former is a based64 encoded result of a binary array, which has pre-defined pattern. This reduces the generated password space and produces weaker password than you expect in the giving size.
The latter command explanation
LC_ALL=C: in some locale,
a-zcontain some multiple byte character which are not supported by
trcommand. Thus, error message is printed.
-dmeans delete character in a given set.